Apache POI xls column Remove

前端 未结 5 484
孤城傲影
孤城傲影 2020-12-17 17:47

I don\'t find how to remove a column with the Apache POI API.
I would appreciate a sample code or help on this point.

5条回答
  •  [愿得一人]
    2020-12-17 18:12

    I think you have to go down each HSSFRow and call HSSFRow.getCell and then HSSFRow.removeCell. The API is oriented towards rows, rather than columns, and very few operations work at the whole column level.

    Sample code (untested):

    HSSFSheet sheet = ...
    int colToRemove = 5;
    Iterator rowIter = sheet.iterator();
    while (rowIter.hasNext()) {
       HSSFRow row = (HSSFRow)rowIter.next();
       HSSFCell cell = row.getCell(colToRemove);
       row.removeCell(cell);
    }
    

提交回复
热议问题