如何在Apache poi中设置多个单元格的样式



我正在弄清楚如何使用单元格范围设置多个单元格的样式。 请参阅我的代码以了解我当前的代码。提前感谢那些想帮助我的人。

for (int counter = 0; counter < ColumnList.length; counter++) {
SXSSFCell cell = currentRow.createCell(counter);
if (counter == 0) {
cell.setCellValue(String.valueOf(rowNum));
cell.setCellStyle(cellStyle);
} else {
String columnValue = ColumnList[counter];                 
String cellValue = rs.getString(columnValue);
cell.setCellValue(cellValue);
cell.setCellStyle(cellStyle);
}

}

文档中有一个CellRangeAddress

,其中包含您可以使用的构造函数:

CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol) 

这是完成的。在多个单元格中应用 cellStyles 的更好方法是按行。 文档中有一个 setRowStyle,您可以在一行中应用 Styles 并循环直到它到达最后一行。

最新更新