简体   繁体   English

COMException故障

[英]COMException Breakdown

Does anyone know if a site (even non-Microsoft), that has details on COMExceptions/HRESULTS. 有谁知道一个站点(甚至是非Microsoft)是否有COMExceptions / HRESULTS的详细信息。

When I attempted to Save my Excel Workbook after using the Copy() function, I received this error: 当我尝试使用Copy()函数后保存Excel工作簿时,出现以下错误:

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

PS I'm doing this in a tight loop for 10K+ files, but reading the files worked out fine, but saving them is proving to be not fun. PS我正在紧密地处理10K +个文件,但是读取文件效果很好,但是事实证明保存起来并不有趣。

Also, if anyone has had the issue of Excel hemorrhaging memory when you use the Copy() function let me know. 另外,如果有人在使用Copy()函数时遇到Excel出血内存的问题,请告诉我。

Thanks! 谢谢!

PSS If anyone needs further clarification please let me know PSS如果有人需要进一步澄清,请告诉我

Edit 1 编辑1

Here's what's going on. 这是怎么回事。 I've been asked to update some XLS files (10K+ in fact), by copying the Active Sheet to a new Sheet (same Workbook) and update the original Sheet by performing some conversion. 我被要求通过将活动工作表复制到新工作表(相同的工作簿)来更新一些XLS文件(实际上是10K +),并通过执行一些转换来更新原始工作表。 The problem comes when I save the Workbook. 当我保存工作簿时出现问题。

Here is some excerpts from my application: 这是我的应用程序的摘录:

///.... 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();
    }
}

If you break down the HRESULT value, the facility code is FACILITY_CONTROL , and the error code is 1004. From some online searching, it appears that this code is generated for a variety of different errors, some of which seem related to copying worksheets programmatically (see for example this KB article ). 如果您分解HRESULT值,则设施代码为FACILITY_CONTROL ,错误代码为1004。通过一些在线搜索,似乎此代码是针对各种不同的错误生成的,其中一些似乎与以编程方式复制工作表有关(例如,请参阅此知识库文章 )。

It might help to post more details about what you're doing, or search online for this HRESULT and see what problems others may have had which look similar to what you're doing. 这可能有助于发布有关您正在做的事情的更多详细信息,或者在网上搜索此HRESULT并查看其他人可能遇到的与您正在做的事情相似的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM