I have Windows 10 OS, Excel 2016 and working on Visual Studio 2017.
I'm using Microsoft Excel 16.0 Object Library, version 1.9.
I want to save 50 rows having 2 columns in Excel file.
I get error hresult '0x800a03ec' on saveas method.
I have seen more than 25+ links till now, which are previously associated with the same error, but no clue.
Here is my code:
object misValue = System.Reflection.Missing.Value;
var excel = new Application();
// for making Excel visible
excel.Visible = false;
excel.DisplayAlerts = false;
// Creation a new Workbook
var excelWorkBook = excel.Workbooks.Add(Type.Missing);
// Work sheet
var excelSheet = (Worksheet)excelWorkBook.ActiveSheet;
excelSheet.Name = "xxxxx";
excelSheet.Cells[1][1] = "head1";
excelSheet.Cells[1][2] = "head2";
for (int i = 0; i < list.Count; i++)
{
excelSheet.Cells[i + 2][1] = list[i].xxx;
excelSheet.Cells[i + 2][2] = list[i].yyy;
}
excelSheet.SaveAs(@"E:\data.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue);
excel.Quit();
Marshal.ReleaseComObject(excelSheet);
Marshal.ReleaseComObject(excelWorkBook);
Marshal.ReleaseComObject(excel);
Need help.
Edit:
1) xls or xlsx, none of them works.
2) Based on some previous answers found, I tried this too: Console Root -> Computers -> DCOM Config -> Microsoft Excel Application -> Not found, triple checked.
Someone please try to apply the same scenario in your machine & let me know if you can find the answers.