如何使用Java和apache poi选择excel中的所有单元格

问题描述 投票:0回答:2

我创建了一个excel表并给它一些数据。现在我必须选择excel表中的所有单元格,这样我就可以立即将文本包装到所有单元格中。存储在Excel工作表中的数据是动态的。有人可以帮助我。我正在使用Java和Apache POI。

谢谢阅读!

java apache-poi
2个回答
2
投票

无需在Apache POI中选择单元格。您应该迭代它们并执行您想要的某些操作。

看看这个迭代示例:https://poi.apache.org/spreadsheet/quick-guide.html#Iterator

在你的情况下,它将是这样的:

    for (Row row : sheet) {
        for (Cell cell : row) {
            cell.getCellStyle().setWrapText(true);
        }
    }

0
投票

试试这个:

CellRangeAddress region = new CellRangeAddress(6, 8, 1, 10); //CellRangeAddress(startRow,endRow,startCell,endCell)
RegionUtil.setWrapText(true, region, sheet);

要么

CellRangeAddress region = CellRangeAddress.valueOf(A6:J8); 
RegionUtil.setWrapText(true, region, sheet);

Check this documentation on poi.apache.org

© www.soinside.com 2019 - 2024. All rights reserved.