We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Find last appearance of cetain text in excel file

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Our application use Aspose.cells version for creating excel reports (based on excel template).

Can you please guide me how to find last appearance of cetain text in excel file.



You need to use your own code to search the last occurring of the string/text in the cells. See a sample code below:

Workbook workbook = new Workbook(“e:\test\Book1.xls”);
WorksheetCollection worksheets = workbook.Worksheets;

Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
ArrayList al = new ArrayList();
Aspose.Cells.Cell foundcell;
string prevcell = CellsHelper.CellIndexToName(cells.MaxDataRow, cells.MaxDataColumn);
string datatosearch = “DATA”;

foundcell = cells.FindString(datatosearch, cells[prevcell],true); //Find the last occurance of the searched data
catch (Exception ee)



I tried to use the above code with no success.

The parameter 'prevcell' has incorrect value ('BV188') and when I try to find the require string I got null.

On my code I'm trying to find last appearance of the word 'Services' (Cell C185)

Please see attached excel file



After an initial test using your file I can find the issue as you have mentioned. I have logged a ticket with an id: CELLSNET-40155. We will look into it soon.

Thank you.


1 - Please change your code as the following:


Worksheet worksheet = workbook.Worksheets[“Report”];

FindOptions fo = new FindOptions();

fo.CaseSensitive = false;

Cells cells = worksheet.Cells;

ArrayList al = new ArrayList();

string datatosearch = “Services”;

fo.SearchNext = false;

fo.LookAtType = LookAtType.EntireContent;

Cell foundcell = cells.Find(datatosearch, null,fo);

2 - or please use Cell foundcell = cells.FindString(datatosearch, null, false);

3 - string prevcell = CellsHelper.CellIndexToName(cells.MaxDataRow, cells.MaxDataColumn);

There are some hidden columns in the worksheet "report"

The value of the cell "BV5" is 15, so the cells.MaxDataColumn is "BV".

If you want to find the last cell in the worksheet, please use Cells. LastCell

Thanks a lot!