【问题标题】:Saving to excel file causes error in c# windows保存到 excel 文件会导致 c# windows 中的错误
【发布时间】:2012-04-22 19:39:21
【问题描述】:

代码如下:

try
{
    if (File.Exists("c:\\Reports\\" + fileName))
    {
        File.Delete("c:\\Reports\\" + fileName);
    }
    _book.SaveAs("c:\\Reports\\" + fileName, Excel.XlFileFormat.xlWorkbookNormal,
                   null, null, false, false, Excel.XlSaveAsAccessMode.xlShared,
                   false, false, null, null, null);
}
catch (Exception ee)
{
    throw ee;
}

关于保存为 excel 格式。我收到以下错误如下..

System.AccessViolationException:试图读取或写入受保护的内存。这通常表明其他内存已损坏。

我使用的是 MS Office 2000 版。

Dll 使用的是 Interop.excel 1.4.0.0

使用 Visual Studio 2008 + c# 控制台应用程序

【问题讨论】:

  • 您正在检查C:\Reports\fileName 是否存在,然后尝试删除C:\fileName。是错字吗?
  • 最好重新计算您的nullnull 序列。
  • 您是否尝试将 ConflictResolution 参数设置为 xlLocalSessionChanges?

标签: c# .net windows excel console


【解决方案1】:

使用 _book.SaveCopyAs("c:\Reports\" + 文件名)

【讨论】:

    猜你喜欢
    • 2012-04-28
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 2017-01-06
    相关资源
    最近更新 更多