我正在尝试从 excel 文件中删除一行,但不能这样做,请参阅此处的代码
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)