简体   繁体   English

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

[英]How to style multiple cell in Apache poi

I'm figuring out how to style multiple cell using cell range. 我正在弄清楚如何使用单元格范围来设置多个单元格的样式。 see my code for my current code. 查看我的代码以获取当前代码。 Thanks in advance for those who want to help me. 在此先感谢您想要帮助我的人。

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) 

This is done. 这个完成了。 A better way of applying cellStyles in multiple cell is by row. 在多个单元格中应用cellStyles的更好方法是按行。 There is a setRowStyle on the docs which you can apply Styles in a row and loop until it reach the last row. 在文档上有一个setRowStyle,您可以在其中连续应用样式并循环直到它到达最后一行。

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

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