Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

c# - Exception from HRESULT: 0x800A03EC Error while saving Excel file

I am saving data on button's click event and below is code:

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;

object misValue = System.Reflection.Missing.Value;
String st = System.IO.Directory.GetCurrentDirectory() + "\A.xlsx";

xlApp = new Excel.ApplicationClass();

xlWorkBook = xlApp.Workbooks.Open(st, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

int i = 6;
for (i = 6; i < 10; i++)
{
    xlWorkBook.SaveAs(st, XlFileFormat.xlExcel9795, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlShared, misValue, misValue, misValue, misValue, misValue);
MessageBox.Show(xlWorkSheet.get_Range("L" + @i, "L" + @i).Value2.ToString());
}

xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();

When I am saving it, it gives me error:

HRESULT: 0x800A03EC Error while saving Excel file

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As I understand at Saving an Excel File Exception from HRESULT: 0x800A03EC Exception raised when arguments of method SaveAs are wrong. Please review your arguments at:

xlWorkBook.SaveAs(st1, XlFileFormat.xlExcel9795, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlShared, misValue, misValue, misValue, misValue, misValue);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...