kb_*_*kb_ 10 c# excel excel-2010
我有一个从数据库表创建Excel文件的小程序,Excel 2013它运行良好,但我现在需要它用于Excel 2010现在当我将"格式"添加到NumberFormatLocal(range.NumberFormatLocal = format;)时,我得到以下异常当我使用时会出现同样的异常range.NumberFormat = format;
例外:
错误消息:System.Runtime.InteropServices.COMException(0x80020005):键入冲突.(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;
}
Run Code Online (Sandbox Code Playgroud)
我的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%";
Run Code Online (Sandbox Code Playgroud)
更新:
我已经尝试使用已经public const string TEXT = "@";只有格式,但同样的错误来了
更新2:
只有表必须有很多次才会发生错误.当我使用例如一个1000表的表它没有问题,一切正常,如果我使用200.000表的一个表发生错误
更新3:
[![NumberFormat和一个单元格的值[1]](https://i.stack.imgur.com/XweNy.png)
我试图只使用标准格式进行测试,发生以下错误:
错误消息:System.OutOfMemoryException:没有足够的内存可用于继续该程序.
小智 1
是否可能是您向 Excel 传递的某些内容被解释为对于 Excel 2010 中的整数数据类型来说太大的整数?例如,也许行号?通过加载 32,760 行进行测试,然后加载 32,770 行,因为在 XL 2010 中整数最多只能达到 32,767 行。值得一试:o)
| 归档时间: |
|
| 查看次数: |
302 次 |
| 最近记录: |