我有一个从数据库表创建Excel文件的小程序,Excel 2013它运行良好,但我现在需要它用于Excel 2010现在我得到以下异常,当我将“格式”添加到NumberFormatLocal(range.NumberFormatLocal = format;
)
当我使用range.NumberFormat = format;
例外:
错误消息:System.Runtime.InteropServices.COMException(0x80020005):键入Conflict。 (HRESULT的例外:0x80020005(DISP_E_TYPEMISMATCH)) 在System.RuntimeType.ForwardCallToInvokeMember(String memberName,BindingFlags flags,ObjectTarget,Int32 [] aWrapperTypes,MessageData& msgData)
功能:
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;
SetMessage($"{selectedTableItem.TableName} {j} von {results.Item3.Count}", LogHelper.NotificationType.Information);
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)];
SetMessage($"{results.Item3.Count * results.Item1.Count} Zellen werden formatiert....", LogHelper.NotificationType.Information);
range.NumberFormatLocal = format;
range.Value = values;
}
我的Excel类型:
public const string INT = "0";
public const string TEXT = "@";
public const string GENERAL = "General";
public const string STANDARD = "Standard";
public const string Date1 = "m/d/yyyy";
public const string DATE2 = "TT.MM.JJJJ";
public const string DATE3 = "T.M.JJ h:mm;@";
public const string DATETIME = "d/m/yy h:mm;@";
public const string DOUBLECO1 = "#.##0,00";
public const string DOUBLECO2 = "0,00";
public const string DOUBLEPO1 = "#0,##0.00";
public const string DOUBLEPO2 = "0.00";
public const string CUSTOM = "#,##000";
public const string CURRENCYEU1 = "#,##0,00 _€";
public const string CURRENCYEU2 = "#,##0 _€";
public const string CURRENCYEU3 = "#,##0,00 €";
public const string CURRENCYDO1 = "#,##0.00 _$";
public const string CURRENCYDO2 = "#,##0 _$";
public const string CURRENCYDO3 = "#,##0.00 $";
public const string PERCENTAGE1 = "0.00%";
public const string PERCENTAGE2 = "0.0%";
public const string PERCENTAGE3 = "0%";
更新
我已经尝试使用public const string TEXT = "@";
作为唯一的格式,但同样的错误来了
更新2:
只有在表必须进行多次调用时才会出现错误。当我使用例如1000的表时,它没有问题并且一切正常,如果我使用200.000的表,则发生错误
更新3:
[
我尝试仅使用标准格式进行测试,发生以下错误:
错误消息:System.OutOfMemoryException:没有足够的内存可用于继续程序。
答案 0 :(得分:1)
您是否正在将某些内容传递给Excel,它正在解释为整数对于Excel 2010中的整数数据类型来说太大了? 也许行号例如?测试它是通过加载32,760行然后32,770行整数只在XL 2010中达到32,767。值得一试:o)
答案 1 :(得分:-2)
It depends on the file-format you use:
In Excel 2010, the maximum worksheet size is 1048576 rows by 16384 columns when using XLSX.
However You cannot generate this in the older XLS format, since it is still limited to 65,536 rows.