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();
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); } .... }