![](/img/trans.png)
[英]how to get last column value of respective row of excel sheet in java using Apache POI
[英]How to get Specific Cell Value from Excel With Respect To Row And Column Value using Java POI
我有一張Excel工作表,
i)我想搜索第一個元素,並假設第一個元素根據圖片為“ double”,
ii)然后通過相同的迭代,我迭代第一行(即行0),然后發現“大小(以字節為單位)”。 然后,我想要相對於行和列值的特定單元格值,該值是通過迭代即“原始”在上面搜索的。 我如何使用Apache POI獲得該信息。 請幫忙。 提前非常感謝
1-代表第一次搜索列值
2-表示第二次搜索行值
3-代表我需要的輸出
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.
我不完全理解您的問題。 但是,下面的代碼是您所期望的嗎?
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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.