【发布时间】:2011-12-05 04:20:41
【问题描述】:
我为复印表编写了一个 c# 程序。当我调用 WorkSheet.Copy 方法直到 105 次时,我得到了异常错误(0x800A03EC)。 这是我的 sn-p 代码:使用 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);
}
}
我找不到任何解决方案。有人可以给我一个提示来解决这个问题吗? 非常感谢。
【问题讨论】:
-
如果一开始失败,请再次调用它... 105 次... 您是否在您使用的界面上下文中查看了 HRESULT 以查看它指示的错误?跨度>