Find Excel cell by text in Apache POI

I want to find a cell in an excel sheet by its text. The text is similar to %t :

 sheet.findCell("%t"); // pseudo-code, not working 

My goal is to provide the user with the opportunity to provide a template in which data is written. Colors and fonts, as well as the position of the data can be customized by the user in the Excel file. This cell %t is the upper left corner of the data table.

Additional question: is there a more elegant way to do this job?

EDIT I repeat the rows and cells to find them. I'm afraid this is not very effective, but it still works:

 public static Cell findCell(XSSFSheet sheet, String text) { for(Row row : sheet) { for(Cell cell : row) { if(text.equals(cell.getStringCellValue())) return cell; } } return null; } 
+4
source share
1 answer

You can iterate through the cells of a worksheet and examine the contents. I do not think there is a simpler method.

+4
source

All Articles