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)
使用更新的apache-POI版本... – Sankumarsingh
我正在使用jar poi-3.2 –
現在我正在使用poi版本3.5的工作 –