如何使用Java Apache POI在Excel工作表中隐藏以下未使用的行?

Yug*_*dle 4 java excel rows apache-poi

我正在使用数据库中的数据填充模板Excel工作表:

 for (Map<String, Object> resultRow : dbResults) {
        if ((currentRow = sheet.getRow(currentDataRow)) == null) {
            currentRow = sheet.createRow(currentDataRow);   // Creates a new row.
        }
        //currentRow.getRowStyle().setHidden(false);

        for (int i = 0; i < resultColumns; i++) {
            currentCell = currentRow.getCell(i, Row.CREATE_NULL_AS_BLANK);
            setCellValue(currentCell, resultRow.get(dbcolumnNames[i]));
        }
        currentDataRow += 1;
    }

// How to hide all empty/Un-used rows following currentDataRow ?
Run Code Online (Sandbox Code Playgroud)

旨在实现:

  • 我想要隐藏填充行后面的未使用行吗?
  • 所有填充行必须可见.
  • 例如:如果填充了第1 100个数据行,则应隐藏101之后的行.

请帮忙 !!

小智 5

Row r = sheet.getRow(indexRow);
if ( r!=null ) {
    r.setZeroHeight(true);
}
Run Code Online (Sandbox Code Playgroud)

  • 从我的测试中,这完全对应于行标题右键单击菜单中可用的隐藏/显示行功能. (2认同)