2

我为复印表编写 ac# 程序。当我调用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);
    }
}

我找不到任何解决方案。有人可以给我一个提示来解决这个问题吗?太感谢了。

4

1 回答 1

0

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

你为什么不尝试使用一个开源的 excel 文件阅读器并使用它们做所有事情呢?速度会飞涨,我保证你不会得到这些错误!

于 2011-12-05T05:02:21.883 回答