繁体   English   中英

如何使用Java和Apache POI在Excel中选择所有单元格

[英]How to select all the cells in an excel using Java and apache poi

我创建了一个Excel工作表并为其提供了一些数据。 现在,我必须选择excel工作表中的所有单元格,以便我可以一次将文本换行应用于所有这些单元格。 我存储在excel工作表中的数据是动态的,请有人帮我。 我正在使用Java和Apache POI。

谢谢阅读!

无需在Apache POI中选择单元格。 您应该只遍历它们并执行一些所需的操作。

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

在您的情况下,将是这样的:

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

尝试这个:

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

在poi.apache.org上查看此文档

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM