2011-10-11 143 views
4

我正在使用XSSF访问.xlsx格式。提取行数据和单元格数据正在被Apache POI - XSSF:Row.getCell()

Row.getCell(1) // to get the first cell data. 

做的是有没有办法访问诸如

Row.getCell(A) or Row.getCell(AC). 

这个细胞就会非常有帮助,我访问列。 任何人都可以告诉我怎么做?

回答

4

我认为您正在寻找的主要类是CellReference - 它处理在面向用户的引用(如“B2”)之间转换为像row = 1,col = 1这样的文件格式引用。有上有一个静态方法来处理您的具体使用情况,convertColStringToIndex

您的使用情况下,你想要的代码类似

Cell c = row.getCell(CellReference.convertColStringToIndex("G")); 
+3

@Rajath你不觉得是时候把它作为最好的答案吗? ;) –

3

使用其引用的问题是关于伸出一只电池,如果我没错。

Sheet referenceSheet = workbook.getsheet("Sheet name your intrested in"); 

CellReference ref = new CellReference("C24"); 
Row row = referenceSheet.getRow(ref.getRow()); 
// null check for the row 
if(row != null) 
{ 
Cell cell = row.getCell(ref.getCol()); 
} 

通过这种方式,我们可以使用其引用来引用单元格。