com 异常 HRESULT:0x800A03EC

发布于 2024-12-19 15:40:15 字数 1691 浏览 2 评论 0原文

我为复印表编写了 c# 程序。当我调用 WorkSheet.Copy方法直到105次。 这是我的代码片段:使用 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);
    }
}

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

I write a c# program for copy sheet. I got the exception error(0x800A03EC) when I call WorkSheet.Copy method until 105 times.
This is my snippet code: using 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);
    }
}

I can't found any solution about this. Could someone give me a hint to solve this problem?
Thank you so much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2024-12-26 15:40:15

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

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

Possibly you have some corrupted Excel registry entries or so?

Why don't you try to use an open source reader of excel files and do everything using them? The speed would skyrocket and i guarantee you would not get these errors!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文