How to delete excel sheet using jxl & java

1.9k views Asked by At

I am trying to delete an excel sheet with jxl jar file using java . But i am not able to understand how to do it. I am not getting any delete or remove method in jxl

2

There are 2 answers

0
Pedi On

You can remove the sheet using the removeSheet method... Sample code,

 public static String removeWorksheet(String p_filename,
                                         int   p_index) throws Exception
   {
    try
     {
       Workbook oldwb =  Workbook.getWorkbook(new File(p_filename));

       WritableWorkbook wb = (WritableWorkbook) Workbook.createWorkbook(new File(p_filename),oldwb);

       wb.removeSheet(p_index);
       wb.write();  // Don't forget this...
       wb.close();  
       return "success";      
     }
    catch(Exception e)
     {
       return "error"+e+e.getMessage();
     }            
   }
}
0
Umesh Kumar On

Ne need to JXL to delete excel file you can java for it. Its quite easy