Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不应该';该列是否以特殊字符开头?_C#_Excel_Excel Interop - Fatal编程技术网

C# 不应该';该列是否以特殊字符开头?

C# 不应该';该列是否以特殊字符开头?,c#,excel,excel-interop,C#,Excel,Excel Interop,我正在使用.xls格式的Excel工作表并将数据写入其中。问题是,每当数据不是以字母开头时,都会提示我不同的错误 例如:当我的列数据以=?us ascii?Q?Google关键字?=开头时,它引发了一个异常: Exception from HRESULT: 0x800A03EC 当我的数据类似于原始消息主题时,错误是: Not enough storage is available to complete this operation. (Exception from HRESULT:

我正在使用.xls格式的Excel工作表并将数据写入其中。问题是,每当数据不是以字母开头时,都会提示我不同的错误

例如:当我的列数据以=?us ascii?Q?Google关键字?=开头时,它引发了一个异常:

 Exception from HRESULT: 0x800A03EC  
当我的数据类似于原始消息主题时,错误是:

Not enough storage is available to complete this operation. (Exception from HRESULT: 0x8007000E (E_OUTOFMEMORY))
这就是我写数据的方式:

 foreach (AllCasesReplies infoList in allCasesReplies)
  {
      n = 0;
      mWorkSheet.Cells[l + m, ++n] = infoList.id;
      mWorkSheet.Cells[l + m, ++n] = infoList.replies;
      m++;
   }
这是我清理对象的方式:

private static void SaveAndCollecttheGarbage(Microsoft.Office.Interop.Excel.Application excelApp, string path, Microsoft.Office.Interop.Excel.Sheets sheet)
{
        excelApp.Columns.AutoFit();
        mWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
        Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
        Missing.Value, Missing.Value, Missing.Value,
        Missing.Value, Missing.Value);
        mWorkBook.Close(true, Missing.Value, Missing.Value);
        sheet = null;
        mWorkBook = null;
        excelApplication.Quit();
        GC.WaitForPendingFinalizers();
        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();
}
所以我试着省略这些数据,它们工作得很好

是否存在列必须以特定字符开头的规则?如果是,这些规则是什么?

如果在具有常规格式的excel单元格中键入“?”,excel会自动调用并将其解释为公式。在将文本插入单元格之前,需要更改单元格格式

比如:

foreach (AllCasesReplies infoList in allCasesReplies)
  {
      n = 0;
      Microsoft.Office.Interop.Excel.Range range1 = mWorkSheet.Cells[l + m, ++n] as Range;
      range1.NumberFormat = "@";
      range1.Value2 = infoList.id;

      Microsoft.Office.Interop.Excel.Range range2 = mWorkSheet.Cells[l + m, ++n] as Range;
      range2.NumberFormat = "@";
      range2.Value2 = infoList.replies;

      m++;
   }

Excel中的公式以什么开头?你如何摆脱那个角色。。。您在编写excel时使用的是哪一个库?我不明白您的意思?我没有使用任何公式。如果你问我是如何省略这些列的,我没有在“列表”中添加我正在向Excel写入的内容。你是如何将这些内容写入Excel的?从Xml中,我将所需字段添加到列表中,然后在列表中循环并写入Excel对不起,它应该是数字格式。我已经在上面更正了。我可以知道它的实际用途吗?此属性的用途NumberFormat属性设置单元格格式,就像在excel中一样。例如,如果在excel中输入字符串“=?us ascii?Q?Google Keywords?=”,单元格格式为“General”,则会从HRESULT引发完全相同的异常:0x800A03EC。但是,如果将单元格格式设置为“文本”,excel将不会引发异常。同样,当单元格格式为“常规”时,诸如“----------原始消息----------主题:”等文本将被解释为公式。公式内存有限,这将抛出内存不足异常。