首页 文章

Apache POI - XSSF:Row.getCell()

提问于
浏览
4

我正在使用XSSF访问.xlsx格式 . 正在提取行数据和单元格数据

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

有没有办法访问像

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

这对我来说非常有用,可以访问列 . 任何人都可以告诉我这样做的方法吗?

2 回答

  • 3

    我认为你正在寻找的主要类是CellReference - 它处理面向用户的引用(如"B2")之间的转换为文件格式引用,如row = 1,col = 1 . 那里有一个静态方法来处理你的确切用例,convertColStringToIndex

    对于您的用例,您需要类似的代码

    Cell c = row.getCell( CellReference.convertColStringToIndex("G") );
    
  • 4

    如果我没有错,问题是如何使用它的引用来扩展单元格 .

    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());
    }
    

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

相关问题