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