Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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# com异常HRESULT:0x800A03EC_C#_Excel_Copy_Worksheet - Fatal编程技术网

C# com异常HRESULT:0x800A03EC

C# com异常HRESULT:0x800A03EC,c#,excel,copy,worksheet,C#,Excel,Copy,Worksheet,我写了一个c程序用于复印纸张。当我调用方法直到105次时,我得到了异常错误0x800A03EC。 这是我的代码片段:使用Microsoft.Office.Interop.Excel private void CreateSheet(string dst_fileName) { object cell1 = "A2"; ApplicationClass app = null; Workbook book = null; Worksheet sheet = null

我写了一个c程序用于复印纸张。当我调用方法直到105次时,我得到了异常错误0x800A03EC。 这是我的代码片段:使用Microsoft.Office.Interop.Excel

private void CreateSheet(string dst_fileName)
{
    object cell1 = "A2";

    ApplicationClass app = null;
    Workbook book = null;
    Worksheet sheet = null;
    Worksheet sheet_to_copy = null;
    int i=0;

    try
    {
        app = new ApplicationClass();
        app.Visible = false;
        app.ScreenUpdating = false;
        app.DisplayAlerts = false;

        book = app.Workbooks.Open(dst_fileName, 0, false, 5, "", "", true,
                                  XlPlatform.xlWindows,
                                  "\t", false, false, 0, true, 1, 0);

        // Reference to the worksheet
        sheet_to_copy = (Worksheet)book.Worksheets[1];

        for(;i<listViewPrg.Items.Count;i++)
        {
            sheet = (Worksheet)book.Worksheets[book.Worksheets.Count];
            // Copy the worksheet to the end of the worksheets
            sheet_to_copy.Copy(Missing.Value, sheet);
            sheet.Name = "NewSheet(" + book.Worksheets.Count + ")";
        }
        book.SaveAs(dst_fileName, Missing.Value, Missing.Value, Missing.Value,
                    Missing.Value, Missing.Value, XlSaveAsAccessMode.xlNoChange, Missing.Value,
                    Missing.Value, Missing.Value, Missing.Value, Missing.Value);

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
    finally
    {
        QuitExcel(app);
    }
}
我找不到任何解决办法。有人能给我一个提示来解决这个问题吗?
非常感谢。

您可能有一些损坏的Excel注册表项或其他


为什么不尝试使用excel文件的开源阅读器,并使用它们做所有事情?速度会突飞猛进,我保证你不会犯这些错误

您可能有一些损坏的Excel注册表项之类的


为什么不尝试使用excel文件的开源阅读器,并使用它们做所有事情?速度会突飞猛进,我保证你不会犯这些错误

如果一开始你失败了,再打一次电话。。。105次。。。您是否在正在使用的接口的上下文中查找该HRESULT以查看它指示的错误?如果最初失败,请再次调用它。。。105次。。。您是否在正在使用的接口的上下文中查找了该HRESULT,以查看它指示的错误?