I
Invalid index. (Exception from HRESULT:
Hi,
I am trying to export data to excel files using excel 12.0
The code is as follows:
Excel.Application xlApplication = new Excel.Application();
Excel.Workbooks xlWorkbooks;
Excel.Workbook xlWorkbook;
Excel.Sheets xlSheets;
Excel.Worksheet xlWorkSheet;
xlApplication.Visible = false;
xlApplication.ScreenUpdating = false;
xlApplication.DisplayAlerts = false;
xlWorkbooks = xlApplication.Workbooks;
xlWorkbook = xlWorkbooks.Open(objMapping.ExcelWorkbookName, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0,
true, 1, 0);
xlSheets = xlWorkbook.Sheets;
xlWorkSheet =
(Excel.Worksheet)xlSheets.get_Item(objMapping.MappingDetails[intCount].TemplateSheetName);
The the error is generated at the last line (the above line) of the code
which i have pasted. The same code works fine if generate .xls (2003) files
but gives error if i try to generate .xlsx (2007) files.
Error message : Invalid index. (Exception from HRESULT: 0x8002000B
(DISP_E_BADINDEX))
And to add i have other application using the same method to generate excels
which is working fine with both .xls and .xlsx.
can anybody please help me rectify the issue!!
Thanks in advance!
I am trying to export data to excel files using excel 12.0
The code is as follows:
Excel.Application xlApplication = new Excel.Application();
Excel.Workbooks xlWorkbooks;
Excel.Workbook xlWorkbook;
Excel.Sheets xlSheets;
Excel.Worksheet xlWorkSheet;
xlApplication.Visible = false;
xlApplication.ScreenUpdating = false;
xlApplication.DisplayAlerts = false;
xlWorkbooks = xlApplication.Workbooks;
xlWorkbook = xlWorkbooks.Open(objMapping.ExcelWorkbookName, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0,
true, 1, 0);
xlSheets = xlWorkbook.Sheets;
xlWorkSheet =
(Excel.Worksheet)xlSheets.get_Item(objMapping.MappingDetails[intCount].TemplateSheetName);
The the error is generated at the last line (the above line) of the code
which i have pasted. The same code works fine if generate .xls (2003) files
but gives error if i try to generate .xlsx (2007) files.
Error message : Invalid index. (Exception from HRESULT: 0x8002000B
(DISP_E_BADINDEX))
And to add i have other application using the same method to generate excels
which is working fine with both .xls and .xlsx.
can anybody please help me rectify the issue!!
Thanks in advance!