How to insert a row between two rows in an existing excel with HSSF (Apache POI)

前端 未结 8 1057
自闭症患者
自闭症患者 2020-11-27 02:38

Somehow I manage to create new rows between two rows in an existing excel file. The problem is, some of the formatting were not include along the shifting of the rows.

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 03:37

    Referencing Qwerty's answer, if the destRow isnot null, sheet.shiftRows() will change the destRow's reference to the next row; so we should always create a new row:

    if (destRow != null) {
      sheet.shiftRows(destination, sheet.getLastRowNum(), 1);
    }
    destRow = sheet.createRow(destination);
    

提交回复
热议问题