需要你的帮助...我最近在基于xls或xlsx选项生成excel文档 . 早些时候默认是xls . 然而,我一直面临着以下错误w.r.以xlsx格式生成excel工作表 .
Caused by: **java.lang.reflect.InvocationTargetException**
SystemErr R at sun.reflect.GeneratedConstructorAccessor193.newInstance(Unknown Source)
SystemErr R at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57)
SystemErr R at java.lang.reflect.Constructor.newInstance(Constructor.java:539)
SystemErr R at **org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)**
SystemErr R ... 17 more
SystemErr R **Caused by: java.io.IOException: error: </sst> does not close tag <t>
SystemErr R** at org.apache.poi.xssf.model.SharedStringsTable.readFrom(SharedStringsTable.java:125)
SystemErr R **at org.apache.poi.xssf.model.SharedStringsTable.<init>**(SharedStringsTable.java:102)
SystemErr R ... 21 more
代码片段:
public String getFilename(String formatType){
Workbook workBook = null;
if((".xlsx").equalsIgnoreCase(formatType))
{
workBook = new XSSFWorkbook();
}
else
{
workBook = new HSSFWorkbook();
}
CreationHelper createHelper = workBook.getCreationHelper();
String sb= FormDetails.getFileNm();
if(formatType.equalsIgnoreCase(".xls"))
{
sb=sb.replace(".xlsx",".xls" );
}
FileInputStream file= new FileInputStream(path+"/"+sb);
workBook = WorkbookFactory.create(file);
Sheet sheet = workBook.getSheetAt(0);
File tempFile = new File(path + fileNameSb.toString());
FileOutputStream fos;
fos = new FileOutputStream(tempFile);
workBook.write(fos);
fos.close();
FilePath=path + fileNameSb.toString();
return FilePath;
}----creating a temporary file and storing it in a location
public void createExcel(String formatType)
{
Workbook workBook = null;
if((".xlsx").equalsIgnoreCase(formatType))
{
workBook = new XSSFWorkbook();
}
else
{
workBook = new HSSFWorkbook();
}
String FilePath = getFilename();----retreiving the file and creating a workbook using the inputstream
FileInputStream fileP= new FileInputStream(FilePath);
workBook = WorkbookFactory.create(fileP);---- Exception here!!!!!
}
此外,我不会在excel生成期间始终得到此错误 .
使用的POI版本:
poi-3.9-20121203.jar
POI-excelant-3.9-20121203.jar
poi-ooxml-3.9-20121203.jar
POI-OOXML-架构 - 3.9-20121203.jar
POI暂存器,3.9-20121203.jar