Bug 56973 - Use Sxssf write a xlsx file, but xssfReader read it Nothing
Summary: Use Sxssf write a xlsx file, but xssfReader read it Nothing
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-12 02:22 UTC by Nanan
Modified: 2014-09-27 09:30 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nanan 2014-09-12 02:22:53 UTC
Use the SXSSFWorkbook to produce a xlsx file,But use the usermode XSSF read nothing;
xlsx write code:
SXSSFWorkbook wb = new SXSSFWorkbook(100);
Sheet sh = wb.createSheet();
for(int rownum = 0; rownum < 1000; rownum++){
    Row row = sh.createRow(rownum);
    for(int cellnum = 0; cellnum < 10; cellnum++){
        Cell cell = row.createCell(cellnum);
        cell.setCellValue("test");
    }

}
FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx");
wb.write(out);
out.close();
// dispose of temporary files backing this workbook on disk
wb.dispose();

xlsx read code:
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader(pkg);
ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg);
XMLReader parser =                XMLReaderFactory.createXMLReader();//"org.apache.xerces.parsers.SAXParser");
        handler = new SheetHandler(sst);
        parser.setContentHandler(handler);
        InputStream sheet2 = r.getSheet("rId1");
        InputSource sheetSource = new InputSource(sheet2);
        parser.parse(sheetSource);
        sheet2.close();
Comment 1 Nanan 2014-09-27 09:30:56 UTC
The cell contents in the xlsx files poi generated, is not a string table index, but a real inline string;
so I use the code as bellow can read the xlsx contents;
in the handler's startElement(){
   ....
   if("s".equals(cellType) || "inlineStr".equals(cellType)){
        nextIsString = true;
   } else {
        nextIsString = false;
   }
   ....
}

endElement(){
   ....
   if("s".equals(cellType)){
       int index = Integer.parseInt(lastString);
       lastString = new XSSFRichTextString(sst.getEntryAt(index)).toString();
   } else if("inlineStr".equals(cellType)){
       System.out.println("inline stirng:" + lastString);
   }
   ....
}