Delete an excel sheet using Apache POI

前端 未结 3 1466
轮回少年
轮回少年 2021-02-07 12:43

I have to delete a sheet from the Excel file.

Here\'s my code snippet :

FileInputStream fileStream = new FileInputStream(destFile);
POIFSFileSystem fsPo         


        
3条回答
  •  一个人的身影
    2021-02-07 13:13

    private void removeOtherSheets(String sheetName, XSSFWorkbook book) {       
            for(int i=book.getNumberOfSheets()-1;i>=0;i--){
                XSSFSheet tmpSheet =book.getSheetAt(i);
                if(!tmpSheet.getSheetName().equals(sheetName)){
                    book.removeSheetAt(i);
                }
            }       
    }
    

提交回复
热议问题