COMException细分

有没有人知道,如果一个网站(即使非微软),有详细的COMExceptions / HRESULTS。

当我尝试使用Copy()函数后保存我的Excel工作簿时,收到此错误:

ERROR - Unable to SaveWorkbook() System.Runtime.InteropServices.COMException (0x800A03EC): Document not saved. 

PS我正在为10K +文件在一个严格的循环,但阅读文件工作得很好,但保存它们被certificate是没有乐趣。

另外,如果有人在使用Copy()函数时遇到Excel出血的问题,请告诉我。

谢谢!

PSS如果有人需要进一步澄清,请让我知道

编辑1

这是怎么回事 我被要求更新一些XLS文件(实际上是10K +),通过将活动工作表复制到新工作表(相同工作簿),并通过执行一些转换来更新原始工作表。 我保存工作簿时出现问题。

以下是我申请的一些摘录:

 ///.... UpdateSpreadsheet() Routine Microsoft.Office.Interop.Excel.Workbook wb = null; try { wb = ef.GetWorkbook(fileName, false, true); } catch (Exception ex) { logger.Error(ex.ToString()); } Microsoft.Office.Interop.Excel.Worksheet ws = null; try { ws = wb.Sheets[Foo.WorksheetName] as Microsoft.Office.Interop.Excel.Worksheet; } catch (Exception ex) { logger.Error(ex.ToString()); } bool result = false; if (ws != null) result = ef.CopyWorksheet(ws, Foo.WorksheetName); if (result) { //... update the sheet as appropriate } try { ef.SaveWorkbook(wb, fileName); //eventually this line crashes, it's random, but so far after the 500th file, and I get that COM Exception. //.. update Foo object to reflect copied worksheet } catch (Exception ex) { //something happened, we can't save, so close and destroy the workbook logger.Error("Unable to SaveWorkbook()", ex); } finally { ef.DestoryWorkbook(wb, fileName); ef.DestroyWorksheet(ws); } //// CopyWorksheet() Method public bool CopyWorksheet(Worksheet ws, String sourceSheet) { try { try { Worksheet sheet = GetWorksheet(sourceSheet + " (2)"); //I don't think the below is necessary, but I'm paranoid about memory leaks ExcelTools.OfficeUtil.ReleaseRCM(sheet); sheet = null; return false; } catch (Exception) { ws.Copy(Missing.Value, ws); //this line never errors out } return true; } catch (Exception) { return false; } finally { ws.Activate(); } } /// SaveWorkbook() public void SaveWorkbook(Workbook wb) { if (wb != null) { wb.Save(); } } 

如果您分解HRESULT值,设施代码是FACILITY_CONTROL ,并且错误代码是1004.从某些联机search,看起来此代码是为各种不同的错误生成的,其中一些似乎与编程复制工作表有关请参阅此知识库文章 )。

这可能有助于发布更多关于你在做什么的细节,或者在线search这个HRESULT,并查看其他人可能遇到的与你正在做的事情类似的问题。