com 异常 HRESULT:0x800A03EC
我为复印表编写了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能您有一些损坏的 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!