如何使用Java和apache poi选择excel中的所有单元格
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用Java和apache poi选择excel中的所有单元格相关的知识,希望对你有一定的参考价值。
我创建了一个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);
Check this documentation on poi.apache.org
以上是关于如何使用Java和apache poi选择excel中的所有单元格的主要内容,如果未能解决你的问题,请参考以下文章
org.apache.poi.hssf.usermodel.HSSFWorkbookorg.apache.poi.xssf.usermodel.XSSFWorkbook excel2003 exce
求解!JAVA 使用Apache POI将PPTX转图片出错。见下图
如何使用 Apache POI 和 Java 代码检查 Excel 文件中是不是存在信息