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

如何使用Java Apache POI在Excel工作表中隐藏以下未使用的行?,java,excel,apache-poi,rows,Java,Excel,Apache Poi,Rows,我正在用数据库中的数据填充模板Excel表: for (Map<String, Object> resultRow : dbResults) { if ((currentRow = sheet.getRow(currentDataRow)) == null) { currentRow = sheet.createRow(currentDataRow); // Creates a new row. } //c

我正在用数据库中的数据填充模板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 ?
for(Map resultRow:dbResults){
if((currentRow=sheet.getRow(currentDataRow))==null){
currentRow=sheet.createRow(currentDataRow);//创建新行。
}
//currentRow.getRowStyle().setHidden(false);
for(int i=0;i
实现目标:

  • 我想隐藏填充行后未使用的行?
  • 所有填充的行都必须可见
  • 例如:如果填充了前100个数据行,则应隐藏101及以后的行

请救命

创建工作表时,POI会识别工作表中的逻辑行数。 因此,当您用100行填充它时,它将创建100条记录。当您使用默认布局在Excel中打开XLS时,将显示其余内容,但这些不是POI记录

您必须在最后一条数据记录之后创建一些伪行,如下所示

for (int i=currentDataRow ;i<65000;i++)
                sheet.createRow(i);
为从最后一行到工作表末尾的所有行设置此样式

while (rows.hasNext()){
                Row row1 = rows.next ();
                row1.setRowStyle(hiddenstyle);


            }

poi-3.8-beta4中有
row.setRowStye()
row.getRowStye()

我会试试你的答案,然后再告诉你结果。我不知道发生了什么事<代码>行。未找到setRowStye()方法
。类似地,未找到row.getRowStyle()方法。。事实上,我已经有了一个解决方案,但它不起作用。我不知道为什么-当它在API文档中给出时,但在我的程序中使用时不起作用。天知道!哎呀。。我正在使用最新的3.7。。真奇怪!不能说是3.7版本,但我使用的是3.7 beta3(20100924),它们并不存在。实际上,这是一个解决方案,但不是我想要的!根据我的测试,这与行标题右键单击菜单中的隐藏/显示行功能完全对应。
Row r = sheet.getRow(indexRow);
if ( r!=null ) {
    r.setZeroHeight(true);
}
Row r = sheet.getRow(indexRow);
if ( r!=null ) {
    r.setZeroHeight(true);
}