は、私は私のExcelファイルに追加されたすべての値をフォーマットしたい多くのセルをExcelにフォーマットを適用し、私はこのような「小さな」と「速い」ソリューションがあります。一度
Item2
がList<string>
で、Item3
ですList<List<string>>
if (chkWithValues.Checked && results.Item3.Any())
{
var rows = results.Item3.Count;
var cols = results.Item3.Max(x => x.Count);
object[,] values = new object[rows, cols];
object[,] format = new object[rows, cols];
//All returned items are inserted into the Excel file
//Item2 contains the database types, Item3 the Values
// pgMain shows the progress for the selected tables
for (int j = 0; j < results.Item3.Count(); j++)
{
int tmpNbr = 1;
foreach (string value in results.Item3[j])
{
values[j, tmpNbr - 1] = Converter.Convert(results.Item2[tmpNbr - 1], value).ToString().Replace("'", "");
format[j, tmpNbr - 1] = ExcelColumnTypes.ConvertToExcelTypes(results.Item2[tmpNbr - 1]);
tmpNbr++;
}
pgMain.Maximum = results.Item3.Count();
pgMain.PerformStep();
}
Excel.Range range = xlWorksheet.Range["A3", GetExcelColumnName(cols) + (rows + 2)];
range.Value = values;
range.NumberFormat = format;
}
単一代入して、効率的にNumberFormatを追加するには、私が設定する必要があり、すべての数値フォーマットが含まれている2次元配列、と解決策を見つけました。
問題は、次のエラーメッセージが表示されることです。以上のサイズのセルをフォーマットすると、エラーメッセージ"Unable to set the NumberFormat property of the Range class"
が発生します。
誰かが高速で大量の細胞をエラーなく処理できることを知っていますか?
更新: ExcelColumnTypes.ConvertToExcelTypes
public static string ConvertToExcelTypes(string databaseType)
{
if (DatabaseColumnTypes.DOUBLE.Contains(databaseType))
return DOUBLEPO1;
if (DatabaseColumnTypes.DATE.Contains(databaseType))
return DATE2;
if (DatabaseColumnTypes.INTEGER.Contains(databaseType))
return INT;
return TEXT;
}
DatabaseColumnTypesがconstのか、直接のconstでリストされています。 サンプル:
public const string VARBINARY = "varbinary";
public static List<string> STRING = new List<string>()
{
CHAR,
VARCHAR,
TEXT,
NTEXT,
NCHAR,
NVARCHAR,
BINARY,
VARBINARY
};
あなたはExcelColumnTypes.ConvertToExcelTypes' 'に関する詳細情報を提供することができます動作するはず? – grek40
[関連する質問/回答を参照](http://stackoverflow.com/questions/10801537/unable-to-set-the-numberformat-property-of-the-range-class)私はあなたの実際の金額の数値が制限を超えていないが、Excelが複数のフォーマットオブジェクトを同じ設定でマージするのに失敗していると思われます。したがって、ソリューションは、かつてExcelに導入されたフォーマットを再利用する方法になりそうです。 – grek40
"NumberFormat"がどれほど重要かわかりませんが、NumberFormatLocalを試してみると... – invidicult