0

I have a app that should create a excel spreadsheet and save it. The app works runs without any problems on other machines, including my bosses computer(he has the same ver of office and VS as me). I don't know if this is relevant but I have office 2013 and VS 2012. Edit I'm trying to save as a .xls (exel 97').

 SNIPIT
 public static bool XLSaveAs(ref Excel._Workbook oWBTemplate, string FileName)
    {
        System.IO.FileInfo x = new System.IO.FileInfo(FileName);
        if (x.Exists)
        {
            try
            {
                x.Delete();
            }
            catch
            {
                MyControls.MsgFunctions.WarningMsg("Make sure " + FileName + " is not open.");
                return false;
            }
        }

        try
        {
           if(FileName.Contains(".xlsx"))
                oWBTemplate.SaveAs(FileName);
            else
                //Error occurs here
                oWBTemplate.SaveAs(FileName, Excel.XlFileFormat.xlExcel8);

        }
        catch
        {
            MyControls.MsgFunctions.WarningMsg("Unable to save " + FileName);
            return false;
        }
        return true;
    }

If I take out the try catch statement this is the error I get.

ERROR
COMException as unhandled
Exception from HRESULT: 0x800A03EC
4

1 回答 1

0

我找到了一个适合我的解决方案。我也有不正确的权限来编辑 excel 正在编写的文件夹。向文件夹添加完全控制解决了该问题。如果您遇到类似问题,命令 oWBTemplate.SaveAsCopy() 也会有所帮助。

于 2013-04-22T19:18:59.837 回答