Error: DISP_E_TYPEMISMATCH while interop.excel

S

SuneelP

Subject: DISP_E_TYPEMISMATCH interop.excel

Hi:

I need help in read excel sheet from C# using Interop.Excel.Application
(Excel Data Library 10)
and find & replace a word from a range in a sheet.

I have following code which gives an error "DISP_E_TYPEMISMATCH".

===============
m_objExcel = new Microsoft.Office.Interop.Excel.Application();

// open the workbook object by opening the excel file.
m_objBook = m_objExcel.Workbooks.Open(filePath,
0,
false,
5,
"",
"",
true,
XlPlatform.xlWindows,
"\t",
true,
false,
0,
true,
1,
0);

//m_objBook =
(Microsoft.Office.Interop.Excel._Workbook)(m_objBooks.get_Item(1));
m_objSheets = (Microsoft.Office.Interop.Excel.Sheets)m_objBook.Worksheets;

foreach (Microsoft.Office.Interop.Excel._Worksheet m_objSheet in m_objSheets)
{
m_objRange = m_objSheet.Cells; //m_objSheet.get_Range("A1",
"AZ20");
}
====================

Any help would be appreciated. Thanks you in davance.
SuneelP
 
Z

ZSvedic

Subject: DISP_E_TYPEMISMATCH interop.excel

Hi:

I need help in read excel sheet from C# using Interop.Excel.Application
(Excel Data Library 10)
and find & replace a word from a range in a sheet.

I have following code which gives an error "DISP_E_TYPEMISMATCH".

===============
m_objExcel = new Microsoft.Office.Interop.Excel.Application();

// open the workbook object by opening the excel file.
m_objBook = m_objExcel.Workbooks.Open(filePath,
                                      0,
                                      false,
                                      5,
                                      "",
                                      "",
                                      true,
                                      XlPlatform.xlWindows,
                                      "\t",
                                      true,
                                      false,
                                      0,
                                      true,
                                      1,
                                      0);

//m_objBook =
(Microsoft.Office.Interop.Excel._Workbook)(m_objBooks.get_Item(1));
m_objSheets = (Microsoft.Office.Interop.Excel.Sheets)m_objBook.Worksheets;

foreach (Microsoft.Office.Interop.Excel._Worksheet m_objSheet in m_objSheets)
{
            m_objRange = m_objSheet.Cells; //m_objSheet.get_Range("A1",
"AZ20");}

====================

Any help would be appreciated. Thanks you in davance.
SuneelP

Which line throws the exception?
I don't know if it works for you, but if you have small workbooks you
can use our GemBox.Spreadsheet Free (http://www.gemboxsoftware.com/
GBSpreadsheetFree.htm) Excel component for XLS/CSV/XLSX reading/
writing/reporting.
Automation causes many problems: http://www.gemboxsoftware.com/GBSpreadsheet.htm#Automation

--Zeljko
 

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