c# – excel 2010 Type Conflict NumberFormat

c# – excel 2010 Type Conflict NumberFormat,第1张

概述我有一个小程序,从数据库表创建Excel文件,Excel 2013它工作正常,但我现在需要Excel 2010,现在我得到以下异常,当我将“格式”添加到NumberFormatLocal(范围.NumberFormatLocal = format;) 当我使用range.NumberFormat = format; 例外: Error message: System.Runtime.Interop 我有一个小程序,从数据库表创建Excel文件,Excel 2013它工作正常,但我现在需要Excel 2010,现在我得到以下异常,当我将“格式”添加到NumberFormatLocal(范围.NumberFormatLocal = format;)
当我使用range.NumberFormat = format;

例外:

Error message: System.Runtime.InteropServices.COMException (0x80020005): Type Conflict. (Exception of HRESulT: 0x80020005 (disP_E_TYPEMISMATCH))
At 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 = "#,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%";

更新:

我已经尝试使用公共const string TEXT =“@”;作为唯一的格式,但相同的错误来了

更新2:

该错误只发生在表必须有许多条目.当我使用例如具有1000个条目的表没有问题,并且一切正常,如果我使用具有200.000条目的表,则出现错误

更新3:

[

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

Error message: System.OutOfMemoryException: InsufficIEnt memory available to continue the program.

解决方法 可能是因为您将Excel转换为Excel 2010中整数数据类型的整数太大的整数? 也许行号为例?通过加载32,760行然后32,770作为整数测试它只能在XL 2​​010中达到32,767.值得一试:o) 总结

以上是内存溢出为你收集整理的c# – excel 2010 Type Conflict NumberFormat全部内容,希望文章能够帮你解决c# – excel 2010 Type Conflict NumberFormat所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1259488.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存