FileInputStream fis = new FileInputStream(file);
HSSFWorkbook wordbook = new HSSFWorkbook(fis);//这句就报异常了???
excel文件是我解析导出来的,我再把文件导入就报错,要在文件随便编辑一下保存才不会报这个错误,再进行导入就不会出这个错误。
java.io.IOException: Duplicate name "DocumentSummaryInformation"
at org.apache.poi.poifs.property.DirectoryProperty.addChild(DirectoryProperty.java:266)
at org.apache.poi.poifs.property.PropertyTable.populatePropertyTree(PropertyTable.java:163)
at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:77)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:174)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
at com.huawei.fms.util.ExcelUtil.read2003Excel(ExcelUtil.java:76)
at com.huawei.fms.util.ExcelUtil.read(ExcelUtil.java:49)
at com.huawei.fms.web.action.EmployeeAction.importExcelDate(EmployeeAction.java:154)
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)
HSSFWorkbook wordbook = new HSSFWorkbook(fis);//这句就报异常了???
excel文件是我解析导出来的,我再把文件导入就报错,要在文件随便编辑一下保存才不会报这个错误,再进行导入就不会出这个错误。
java.io.IOException: Duplicate name "DocumentSummaryInformation"
at org.apache.poi.poifs.property.DirectoryProperty.addChild(DirectoryProperty.java:266)
at org.apache.poi.poifs.property.PropertyTable.populatePropertyTree(PropertyTable.java:163)
at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:77)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:174)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:305)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
at com.huawei.fms.util.ExcelUtil.read2003Excel(ExcelUtil.java:76)
at com.huawei.fms.util.ExcelUtil.read(ExcelUtil.java:49)
at com.huawei.fms.web.action.EmployeeAction.importExcelDate(EmployeeAction.java:154)
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)
ByteArrayOutputStream out = new ByteArrayOutputStream();
WritableWorkbook workbook;
workbook = Workbook.createWorkbook(out);
WritableSheet sheet = workbook.createSheet("Sheet1", 0);
sheet.setColumnView(0, 10);
sheet.setColumnView(1, 15);
sheet.setColumnView(2, 5);
sheet.setColumnView(3, 10);
sheet.setColumnView(4, 10);
sheet.setColumnView(5, 10);
for (int i = 0; i < empList.size(); i++)
{
Label label = new jxl.write.Label(0, i, empList.get(i).getName());
sheet.addCell(label);
Label label1 = new jxl.write.Label(1, i, empList.get(i).getPyName());
sheet.addCell(label1);
Label label2 = new jxl.write.Label(2, i, empList.get(i).getSex());
sheet.addCell(label2);
Label label3 = new jxl.write.Label(3, i, empList.get(i).getBirthday());
sheet.addCell(label3);
Label label4 = new jxl.write.Label(4, i, empList.get(i).getEmail());
sheet.addCell(label4);
}
workbook.write();
workbook.close();
}
导出用JXL?
导入用POI?
导入导出同时用POI或者JXL就行了汗……