2013-07-02 68 views
1

我試圖刪除Excel文件的單一行刪除Excel單排,但不能這樣做, 看到這裏的代碼廣東話使用POI

try{ 

    String val = request.getParameter("rdel"); 
    int va = 5; 
    System.out.println("int val"+va); 
    FileInputStream file = new FileInputStream(new File(fileName));  
    HSSFWorkbook wb = new HSSFWorkbook(file); // here exception occurs 
      HSSFSheet sheet = wb.getSheetAt(0);   



     int lastRowNum=sheet.getLastRowNum(); 
     if(va>=0&&va<lastRowNum){ 
      sheet.shiftRows(va+1,lastRowNum, -1); 
     } 
     if(va==lastRowNum){ 
      HSSFRow removingRow=sheet.getRow(va); 
      if(removingRow!=null){ 
       sheet.removeRow(removingRow); 
      } 
     } 

    FileOutputStream out = new FileOutputStream ("D:/task.xls"); 
    wb.write(out); 



     }catch(Exception e){ 
     e.printStackTrace(); 
} 
     return SUCCESS; 
} 

看到異常

org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance 
at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:186) 
at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:328) 
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:271) 
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:196) 
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:312) 
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:293) 
at com.struts.curd.Delete.execute(Delete.java:47) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
+0

使用更新的apache-POI版本... – Sankumarsingh

+0

我正在使用jar poi-3.2 –

+0

現在我正在使用poi版本3.5的工作 –

回答

1

在3.2之後...更新POI版本,最近刪除了此問題(現在是3.9)......希望你不會再次面對這個問題......

有關詳情PLZ檢查here