473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Excel and .find

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.XlSearchDirecti on.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

Aug 2 '06 #1
1 14826
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.

bj************@t-online.de schrieb:
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.XlSearchDirecti on.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
Aug 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hugh McLaughlin | last post by:
Hello everyone and thanks for your help in advance. This is somewhat of a continuation of a thread that I posted about one week ago. the heart of the project requires using ADO.Net to extract...
2
by: scorpion53061 | last post by:
This excel find/replace code works great under Excel 2003 but bombs with an error (pasted below the code) in Excel 2000. Can anyone suggest an alternative to make both happy? I am using vb.net...
0
by: pp | last post by:
I have copied this code from Excel VBA, to use in a VB.net application: Dim r as Excel.Range r=Cells.Find(What:="02/01/2001 22:00:00", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,...
3
by: Lance Hoffmeyer | last post by:
Hi all, I am trying to find the last used column in an excel sheet using win32com: lastcol = sh.UsedRange.Columns.Count works, but only if there is no formatting. I want to allow formatting...
10
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
1
by: fakehitswizard | last post by:
this is the correct way to close excel with C#. I've seen alot of other bogus posts ALL over the web that don't work, how frustrating. string savepath; bool foundPID; int ourPID = 0; int...
7
by: Sol | last post by:
I have to work with an excel file, read only on my machine. I set up the COM class, and it is working all right, but I hit a wall now. I need to search for a given string in the worksheet, using...
7
by: rosshughson | last post by:
I'm lost here. I need to count the number or rows that contain different text. In one column, it will be an exact match to the cell. In the other column, the text will be contained within the cell....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.