0

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

gagan
  • 1
  • 1
  • 2
    Without code no one can help you I'm afraid! – Alan Hay Oct 28 '16 at 17:53
  • 2
    Why are you using nearly 4 year old jars? What happens when you upgrade to the latest versions? – Gagravarr Oct 28 '16 at 19:33
  • This issue doesn't happen every time during excel generation and the challenge was trying to replicate it.. so far so good and hence there was no need of changing these jars..I'd considered the option of upgrading the jars to 3.15.. But I would like to take any suggestions before I would go ahead.. I wanted to know if this really issue with the apache poi or if someone has faced it before – gagan Oct 30 '16 at 16:31

0 Answers0