Excel and .find

B

bjoern.bendler

Hello,

i try a Excel search in C#.

public Excel.Application excelApp = new Excel.ApplicationClass();
public Excel.Worksheet excelWorksheet;

void Button1Click(object sender, System.EventArgs e)
{
Excel.Application excelApp = new Excel.ApplicationClass();

string workbookPath = this.textBox1.Text;
Excel.Workbook excelWorkbook =
excelApp.Workbooks.Open(workbookPath,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

string currentSheet = "Tabelle1";
excelWorksheet =
(Excel.Worksheet)excelSheets.get_Item(currentSheet);

}

void Button2Click(object sender, System.EventArgs e)
{
excelWorksheet.Cells.Find("a","",
Excel.XlFindLookIn.xlValues,Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByRows,Excel.XlSearchDirection.xlNext,
false,null,false);
}

It based on an xls that looks:

a
b
c
d
e
f
g
h
i

Open then Document works fine. But everytime i push the search Button i
get this error:

"Exception System.Runtime.InteropServices.COMException was thrown in
debuggee:
Typkonflikt. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH"

Please help. I found some entries in this group but nothing works...

thanx
Björn
 
A

Anthrax

i get it. here is the correct Excel .find

Excel.Range foundRange = excelWorksheet.Cells.Find("b",
Missing.Value, Missing.Value,
Excel.XlLookAt.xlPart, Missing.Value,
Excel.XlSearchDirection.xlNext,
Missing.Value, Missing.Value, Missing.Value);

my problem was the "Missing.Value" from System.Reflections.
in my first example i tried to implement the "missing"-Values with
"null" or "" and that
doesn' work.
 

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