简体   繁体   English

根据JAVA中的列名从Excel文件获取单元格值

[英]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.

相关问题 根据 java 中的列名从 excel 获取列值 - get column value from excel based on column names in java 如何在Java中使用Excel从column1和column 3获取单元格值并将映射作为键值对放入地图 - How to get the cell values from column1 and column 3 and put in map as key value pair using excel in java 使用 Java 获取所选单元格的 Excel 工作表列名 - get Excel Sheet Column Name of a Chosen Cell using Java 如何使用Java POI从Excel获取有关行和列值的特定单元格值 - How to get Specific Cell Value from Excel With Respect To Row And Column Value using Java POI 如何从JAVA中的excel获取列值? - How to get column value from excel in JAVA? 从excel单元格值中读取并提取文件名 - Read and extract file name from excel cell value 如何使用Java从Excel工作表中获取特定列名(作为参数传递)的最后一个非空单元格的行索引? - How to get the row index of last non-empty cell for a specific column name(passed as an argument) from an excel sheet using java? 如何在 Java 中从 Excel 中的列名中读取值 - how to read a value from Column Name in Excel in Java 如何使用Java从基于第一列名称的CSV文件中获取数据 - How to get data from csv file based on first column name using java 如何从 excel 文件中获取特定的单元格值 - How can I get a specific cell value from an excel file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM