excel 2010types冲突NumberFormat

我有一个小程序,从数据库表创buildExcel文件,使用Excel 2013,它工作得很好,但我现在需要它的Excel 2010,现在我得到以下exception,当我将格式添加到NumberFormatLocal( range.NumberFormatLocal = format; )当使用range.NumberFormat = format;时,会出现同样的exceptionrange.NumberFormat = format;

例外:

错误消息:System.Runtime.InteropServices.COMException(0x80020005):types冲突。 (例外HRESULT:0x80020005(DISP_E_TYPEMISMATCH))在System.RuntimeType.ForwardCallToInvokeMember(stringmemberName,BindingFlags标志,ObjectTarget,Int32 [] aWrapperTypes,MessageData&msgData)

function:

 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; } 

我的Exceltypes:

 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 = "TMJJ 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:

错误只发生在表中有许多entrys。 当我使用例如一个1000表没有问题,所有工作正常,如果我使用一个表200.000 entrys错误发生

更新3:

[ NumberFormat和一个单元格的值[1]

我试图只使用标准格式进行testing,发生以下错误:

错误消息:System.OutOfMemoryException:内存不足以继续该程序。

在这里输入图像描述

难道是你传递给Excel的东西,它被解释为一个整数,对Excel 2010中的整数数据types来说太大了? 也许行数为例? testing它加载32,760行,然后32,770作为整数只有在XL 2​​010 32,767。值得一试:o)

这取决于您使用的文件格式:

在Excel 2010中,使用XLSX时,最大工作表大小为1048576行×16384列。

但是,您不能使用旧的XLS格式生成这个格式,因为它仍然限制在65,536行。