Exception (HRESULT: 0x800AC472) when using Excel.Worksheet.Select after calling Excel.Workbook.SaveAs

前端 未结 3 1138
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 14:32

I\'m opening an xlsx file and saving each sheet into a csv file.

Here is the relevant code for the saving:

int i=0;
foreach (Excel.Worksheet s in app         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 15:32

    I think this is a binding issue, I just surrounded every call (SaveAs, Select) with a:

    bool failed = false;
    do
    {
        try
        {
            // Call goes here
            failed = false;
        }
        catch (System.Runtime.InteropServices.COMException e)
        {
            failed = true;
        }
        System.Threading.Thread.Sleep(10);
    } while (failed);
    

提交回复
热议问题