Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I need to upload an excel file and it'll be any format. I need to find a string in that excel before showing the values in grid view.
For eg:
In one excel, first 5 rows have values and from 6th row onwards, I'll have datas to fill the gridview.
In another excel, first 8 rows have some values and from 10 th row onwards, I'll have datas to fill the gridview.
My question is how to find the string or value from that excel and then load that corresponding value in the grid view.
Posted
Comments
Amir Mahfoozi 3-Jan-12 6:25am    
Start recording a macro and then try to find a text. Then stop recording and goto View > Macros and see what has been saved. You can call that function in Office interop services exactly. This is a general way to understand what to do in Office interop services (either its in Csharp or VB.NET). Good Luck

1 solution

You can use Range.Find Method [^] which is used to finds specific information in a range and returns a Range object that represents the first cell where that information is found.

VB
currentFind = this.Fruits.Find("YourSearchString", missing,
    Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart,
    Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false,
    missing, missing);


Reference Link :- Search for Text in Worksheet Ranges[^]
 
Share this answer
 
Comments
Rajesh Anuhya 3-Jan-12 8:27am    
Good answer ravi +5
RaviRanjanKr 3-Jan-12 8:32am    
Thanks :)
Wendelius 3-Jan-12 14:59pm    
Exactly, 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900