简体   繁体   English

如何使用JAVA获取Excel工作表中指定位置的单元格值

[英]How to get the value of a cell at a specified position in an excel sheet using JAVA

How to get the value of a specific cell from a .xlsm file using java ..?? 如何使用java从.xlsm文件中获取特定单元格的值.. ?? I want to fetch the cell value by specifying the particular row and column for example i need the cell value at row 1 and column C1 or row5 and column C6 ... I am getting the values by specifying the row and column number like this 我想通过指定特定的行和列来获取单元格值,例如我需要第1行和第C1列或第5行和第C6列的单元格值...我通过指定行和列号来获取值,如下所示

XSSFRow row = sheet.getRow(4); // 4 is the row number // 4是行号

cell = row.getCell(4); // 4 is the column number // 4是列号

But this is working only if the sheet has column starting from A,B,C,D...so on...when i try with the same coding to fetach another sheet but it does not work... In this sheet, column starts from C,D,E ... so on 但是只有当工作表有从A,B,C,D开始的列时......这样才有效...当我尝试使用相同的编码来获取另一张纸但它不起作用时......在这张表中,列从C,D,E开始......等等

Can any one help me out to get to know what can i use therr to get the specified result ? 任何人都可以帮助我了解我可以使用什么来获得指定的结果?

You probably want to use the CellReference utility class to help you out. 您可能希望使用CellReference实用程序类来帮助您。

You can then do something like: 然后你可以这样做:

 Sheet sheet = workbook.getSheet("MyInterestingSheet");

 CellReference ref = new CellReference("B12");
 Row r = sheet.getRow(ref.getRow());
 if (r != null) {
    Cell c = r.getCell(ref.getCol());
 }

That will let you find the cell at a given Excel-style reference 这将让您在给定的Excel样式引用中找到单元格

if that sheet has name,u can get the sheet name and use iterator. 如果该工作表有名称,您可以获取工作表名称并使用迭代器。

  Iterator iterator = workSheet.rowIterator();
  while(iterator.next){
       Row row = (Row) iterator.next();
        //u can iterate and use row.getCell(i)
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Java在Excel工作表中打印“空白单元格”相邻单元格值 - Print the Empty cell Adjacent cell value in Excel Sheet using Java 使用 Java 读取 Excel 工作表中的相邻单元格值 - Read the Adjacent cell value in Excel Sheet using Java 使用 Java 获取所选单元格的 Excel 工作表列名 - get Excel Sheet Column Name of a Chosen Cell using Java Java POI:如何查找具有字符串值的Excel单元格并获取其位置(行)以使用该位置查找另一个单元格 - Java POI: How to find an Excel cell with a string value and get its position (row) to use that position to find another cell 如何使用java代码从excel单元格表中获取逗号分隔值 - How to get the comma seperated values from the excel cell sheet using java code 如何从Excel工作表中的单元格中获取数值 - How to get the Numneric Value from a cell in an excel sheet 如何使用java为Excel工作表定义动态单元格范围? - How to define dynamic cell range for Excel sheet using java? 在Java中的Excel工作表中获取单元格的字体颜色 - Get font colour of a cell in excel sheet in java 如何使用Java Excel库从Excel工作表获取日期时间戳记值 - how to get date timestamp value from excel sheet using Java Excel library 如何使用Apache POI获取java中各行excel表的最后一列值 - how to get last column value of respective row of excel sheet in java using Apache POI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM