Reputation: 15
I have an excel sheet,
i) i want to search first element and suppose the first element is "double" according to the picture,
ii) Then with the same iteration i iterate the first row (i.e. row 0) and i found "size(in bytes)". Then i want the specific cell value with respect to row and column value i searched above with the iteration i.e."Primitive". How do i get that using Apache POI. Please help. Lots of thanks in advance
1- represents first search for column value
2- represents second search for row value
3- represents the output i need
FileInputStream excelFile = new FileInputStream(new File(str));
Workbook workbook = new XSSFWorkbook(excelFile);
Sheet datatypeSheet = workbook.getSheetAt(0);
Sheet sheet = workbook.getSheetAt(0);
//Iterator<Row> iterator = datatypeSheet.iterator();
for(Row row : sheet)
{
Cell cell = row.getCell(0);
System.out.println(cell.getStringCellValue());
boolean e = EngineList.add(cell.getStringCellValue());
System.out.println(e);
}
Row currentRow = datatypeSheet.getRow(0);
Cell cell = currentRow.getCell(1);
// System.out.println("crow"+currentRow);
System.out.println("crow"+cell);
System.out.println("crowlastcellnum"+currentRow.getLastCellNum());
if(currentRow.getRowNum()==0)
{
for(int i=1;i<currentRow.getLastCellNum();i++)
{
if (currentRow.getCell(i).getCellTypeEnum() == CellType.STRING) {
System.out.println(currentRow.getCell(i).getStringCellValue());
parameterList.add(currentRow.getCell(i).getStringCellValue());
}
}
System.out.println();
}
//am getting the row values and column values and stored them into arraylist for search.
Upvotes: 0
Views: 3282
Reputation: 131
I did not understand your question completely. But, is the below code is what you expecting?
FileInputStream excelFile;
Workbook workbook;
try {
excelFile = new FileInputStream(new File(fileName));
workbook = new XSSFWorkbook(excelFile);
Sheet datatypeSheet = workbook.getSheetAt(0);
for (Row currentRow : datatypeSheet) {
for (Cell cell : currentRow) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
System.out.print(cell.getStringCellValue() + "||");
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
System.out.print(cell.getNumericCellValue() + "||");
}
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
Upvotes: 0