Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDE

  • Thread starter Invalid index. (Exception from HRESULT:
  • Start date
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!
 
F

filip

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!

Hi,

Do you have Office 2007 installed on your machine? That could be
problem if you don't.
On other hand you can try using GemBox.SPreadsheet - this 3rd party
component doesn't depend on your version of Excel so it could save you
from lot of troubles.
http://www.gemboxsoftware.com/GBSpreadsheet.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top