Help!!!!!! - Find Function not working from C#

  • Thread starter Thread starter andyblum
  • Start date Start date
A

andyblum

I have been enjoying Excel programming but am now hitting a wall. I
simply want to transfer all data from the spreadsheet at runtime. The

spreadsheet is read ever 1 secs on a timer as it has real-time
streaming data inside of it.

I figured the first step was to dynamically figure out a range address
then simply get that range and assign the values to an arraylist.


How do I dynamically figure out a range to do this. The find function
is throwing a COM Interrupt message.


Here is my Find Call


int iMaxRows = excelWorksheet.Cells.Find("*", "A1",
Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart,
Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlPrevious,
false, false, Type.Missing).Row;


It throws a type mismatch on the third to last argument which is
MatchCase an object.
Ive tried


1. Type.Missing
2. 0
3. Declare object var = false and use var


None of it works. Any Suggestions?????


Thank You in advance for reading and hopefully solving.
 
I have been enjoying Excel programming but am now hitting a wall.

You'll hit it more often than you'll like ;-)
I
simply want to transfer all data from the spreadsheet at runtime. The

spreadsheet is read ever 1 secs on a timer as it has real-time
streaming data inside of it.

I figured the first step was to dynamically figure out a range address
then simply get that range and assign the values to an arraylist.

If you want to get all data in an excel sheet, don't use the find
function,
use the Worksheet.UsedRange property instead. It will give you the
range of all cells that either contain something or have a non-default
layout.
This means that you'll also select empty cells, but it's a good start
since you'll like to check cell contents anyway before you start doing
things. Besides, it is the only method I've heard of,

cheers,
Joachim
 
Just posting my solution for future developers to use. THis code works
perfectly and is different then any one described so far.

Excel.Range workingRangeCells = excelWorksheet.get_Range("A1",
Type.Missing);
workingRangeCells =
workingRangeCells.get_End(Excel.XlDirection.xlToRight);
workingRangeCells =
workingRangeCells.get_End(Excel.XlDirection.xlDown);
string downaddress = workingRangeCells.get_Address(false, false,
Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
workingRangeCells = excelWorksheet.get_Range("A1", downaddress);

Andy Blum
 

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

Back
Top