加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – excel 2010 Type Conflict NumberFormat

发布时间:2020-12-15 06:44:43 所属栏目:百科 来源:网络整理
导读:我有一个小程序,从数据库表创建Excel文件,Excel 2013它工作正常,但我现在需要Excel 2010,现在我得到以下异常,当我将“格式”添加到NumberFormatLocal(范围.NumberFormatLocal = format;) 当我使用range.NumberFormat = format; 例外: Error message: System
我有一个小程序,从数据库表创建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 _                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读