com例外HRESULT:0x800A03EC

时间:2011-12-05 04:20:41

标签: c# excel copy worksheet

我为拷贝表编写了一个c#程序。当我调用WorkSheet.Copy方法直到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);
    }
}

我找不到任何解决方案。有人能给我一个提示来解决这个问题吗? 非常感谢你。

1 个答案:

答案 0 :(得分:0)

您可能有一些损坏的Excel注册表项吗?

为什么不尝试使用excel文件的开源阅读器并使用它们执行所有操作?速度会飙升,我保证你不会得到这些错误!