Need your help here... I've recently worked on generation of an excel document based on xls or xlsx option. Earlier it was xls by default. However i've been the facing the below error w.r.to generating excel worksheet in xlsx format.
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
Code Snippet:
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!!!!!
}
Also i don't get this error always during excel generation.
The POI version used:
poi-3.9-20121203.jar
poi-excelant-3.9-20121203.jar
poi-ooxml-3.9-20121203.jar
poi-ooxml-schemas-3.9-20121203.jar
poi-scratchpad-3.9-20121203.jar