Count number of occurrences of string in excel

Hi,


Can you please share sample code to find number of string occurrences in excel using aspose.cell.

Code should scan entire excel file and give number of occurrences

Eg.

Test
Test
Test
Test

If excel has String : “Test” then output should be count: 4.

Thanks,
Sachin Dagar

Hi,


See the sample code to accomplish your task for your reference:
e.g
Sample code:

String filePath = “Book1.xlsx”;

Workbook workbook = new Workbook(filePath);
String strToFind = “Test”;
FindOptions options = new FindOptions();
options.setLookAtType(LookAtType.CONTAINS);
options.setCaseSensitive(false);
int counter = 0;

for (int i = 0; i < workbook.getWorksheets().getCount(); i++)
{
Worksheet worksheet = workbook.getWorksheets().get(i);
Cell found = null;
do
{
found = worksheet.getCells().find(strToFind, found, options);
if (found == null)
break;
counter++;
} while (true);

}

System.out.println("Number of Occurrences: " + counter);

Hope, this helps a bit.

Thank you.

Thanks for the sample code .


Regards,
Sachin