Delete an excel sheet using Apache POI

前端 未结 3 1464
轮回少年
轮回少年 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:06

    Delete a sheet using Apache POI

    //Open file
      FileInputStream inputStream = new FileInputStream(new File(filePath));
      XSSFWorkbook workBook = new XSSFWorkbook(inputStream);
    
    //Delete Sheet
      workBook.removeSheetAt(resultWorkbook.getSheetIndex("SheetToBeDeleted"));
    
    //Save the file
      FileOutputStream outFile =new FileOutputStream(new File(filePath));
      workBook.write(filePath);
      outFile.close();
    

提交回复
热议问题