ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error: DISP_E_TYPEMISMATCH while interop.excel (https://www.excelbanter.com/excel-programming/413619-error-disp_e_typemismatch-while-interop-excel.html)

SuneelP

Error: DISP_E_TYPEMISMATCH while interop.excel
 
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_objBo oks.get_Item(1));
m_objSheets = (Microsoft.Office.Interop.Excel.Sheets)m_objBook.W orksheets;

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

ZSvedic

Error: DISP_E_TYPEMISMATCH while interop.excel
 
On Jul 7, 12:04*am, SuneelP wrote:
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_objBo oks.get_Item(1));
m_objSheets = (Microsoft.Office.Interop.Excel.Sheets)m_objBook.W orksheets;

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/GBSpre...htm#Automation

--Zeljko


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com