[英]Get cell value from Excel file based on the column name in JAVA
I am trying to read an Excel file and get the value of a particular column. 我正在尝试读取Excel文件并获取特定列的值。
I used row.getCell(0),toString()
to get the first column value. 我使用row.getCell(0),toString()
来获取第一列值。 Instead of using the column index, I wanted to use the Column Name. 我不想使用列索引,而是想使用列名。 How can I do this ? 我怎样才能做到这一点 ? getCell
allows only the index to be entered. getCell
仅允许输入索引。 how can I pass the column name. 如何传递列名。 Something like row.getCell(COLUMN_NAME)
类似于row.getCell(COLUMN_NAME)
Looks like you are utilizing apache-poi
for your purpose. 看来您是出于目的使用apache-poi
。 You can use a util class CellReference
, sample usage below: 您可以使用util类CellReference
,以下示例用法:
XSSFSheet ws = wb.getSheet("Sheet1");
CellReference cellReference = new CellReference("A11");
XSSFRow row = sheet.getRow(cellReference.getRow());
if (row != null) {
XSSFCell cell = row.getCell(cellReference.getCol());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.