poi操作xlsx文件删除列方法,求救
目前项目中要POI2.5.1升到3.9,进行xls和xlsx都能操作。
操作xls是用HSSF,但是操作xlsx用XSSF。以下是HSSF的删除列方法,网上有以下提供。
public void removeColumn(HSSFSheet sheet, int removeColumnNum, int removeColumnTotal){
if(sheet == null){
return;
}
for (Iterator<Row> rowIterator = sheet.rowIterator(); rowIterator.hasNext();) {
HSSFRow row = (HSSFRow)rowIterator.next();
HSSFCell cell = row.getCell(removeColumnNum);
if(cell == null){
continue;
}
row.removeCell(cell);
for(int n = removeColumnNum; n < (removeColumnTotal + removeColumnNum); n ++){
int columnWidth = sheet.getColumnWidth(n + 1);
HSSFCell cell2 = row.getCell(n + 1);
if(cell2 == null){
break;
}
sheet.setColumnWidth(n, columnWidth);
row.moveCell(cell2, (short)n);
}
}
}
以上列子的row.moveCell(cell2, (short)n)在项目中是用cell.setcellnum(),poi升级之后已被改用以上方法。但是XSSF里面的XSSFRow没提供moveCell(cell2, (short)n),XSSCell.setcellnum()也是被保护的,不知该如何解决,请大侠帮忙。多谢!