Bug 52622 - we use poi excel xssf usermodel to create a excel2007 xlsx file,then we use xssf eventmodel to read it,the ooxml xml content is not right.
Summary: we use poi excel xssf usermodel to create a excel2007 xlsx file,then we use x...
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-08 03:58 UTC by wangwei
Modified: 2013-08-05 12:34 UTC (History)
0 users



Attachments
the code for creating xlsx file (8.73 KB, application/octet-stream)
2012-02-08 08:36 UTC, wangwei
Details
the poi example file (15.34 KB, application/octet-stream)
2012-02-08 09:08 UTC, wangwei
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wangwei 2012-02-08 03:58:43 UTC
We use poi excel xssf usermodel to create a excel2007 xlsx file,then we use xssf eventmodel to read it,the ooxml xml content is not right.When we read the file with SAX Handler(startElement,endElement,characters and so on),we find the XML content is only like that:
<sst><si><t>content</t></si><si><t>content2</t></si><si><t>content3</t></si></sst>
So we can't process it using OOXML specification.But if the file is created without using POI,it is ok,the xml content is right.

NB:if we make some mistakes when write xml or read xml,please show,thanks in advance,we see the testcases for eventmodel,we use it like that.
Comment 1 Yegor Kozlov 2012-02-08 08:15:30 UTC
Which version of POI? 

I don't quite understand what's wrong. Please post sample code that demonstrates what's wrong:
 1. code that generates a .xlsx file with the XSSF usermodel API
 2. code that reads the created file using SAX. 



Yegor
Comment 2 wangwei 2012-02-08 08:36:24 UTC
Created attachment 28282 [details]
the code for creating xlsx file

use the code to create file,the poi version is poi-3.7-20101029.then you can read it using event sax,you will find the problem.
Comment 3 Yegor Kozlov 2012-02-08 08:38:44 UTC
Try with the latest POI-3.8-beta5. 
Many bugs have been fixed since POI-3.7 including fixes in the XSSF usermodel API.

Yegor
Comment 4 wangwei 2012-02-08 08:59:38 UTC
My reading code like that:
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
// how to by sheet name?
InputStream sheet2 = r.getSheet("rId1");
InputSource sheetSource = new InputSource(sheet2);
parser.parse(sheetSource);
sheet2.close();
return resultSet;

public XMLReader fetchSheetParser(SharedStringsTable sst) throws SAXException {
XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
ContentHandler handler = new SAXSheetHandler(sst);
parser.setContentHandler(handler);
return parser;
}
Comment 5 wangwei 2012-02-08 09:08:08 UTC
Created attachment 28284 [details]
the poi example file

I think i make some mistake.
Because i use the poi example code in the newest poi version to read the previous xlsx file,it is ok.I compare the codes and find some differences:
the poi example use like that:
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage);
i guess it is a important thing,can you tell me why,show me the right usecase of construct the event sax context,and show me something that i need to notice.

NB:no change the poi version,
Comment 6 wangwei 2012-02-08 09:12:23 UTC
please notice that: my wrong code can read the xlsx file without using poi.Thanks in advance.
Comment 7 wangwei 2012-02-08 09:14:33 UTC
no support the handler code,because i make sure that it is not important for the issue.
Comment 8 wangwei 2012-02-08 09:25:24 UTC
also i test it with the newest poi-bin-3.8-beta5-20111217.zip,the same action with the 3.7
Comment 9 wangwei 2012-02-08 09:40:36 UTC
really look forward your reply.Thanks.
Comment 10 Yegor Kozlov 2012-02-09 07:46:40 UTC
I still don't see anything wrong with POI. 

The attached Java program creates a sheet with two cells: A1 with a string value "a" and B1 with a string value "b". 

XLSX2CSV  is based on the event model and can process this file without problems.
The console output:

sheet1 [index=0]:
"a","b"
 
Please confirm that you observe the same results.

The second code snippet is not complete and I cannot compile and verify it. Please post full code and describe what values you expect to see in the output, what is missing, etc. 

You said that files created in Excel 2007 are processed OK. Please attach two sample files:  one created by POI and the other created in Excel 2007 and which is read OK by your program. 

Yegor
Comment 11 wangwei 2012-10-22 01:13:17 UTC
This is ok,and it is my mistake,now you can close it.thanks very much.
Comment 12 Dominik Stadler 2013-08-05 12:34:16 UTC
closed based on the previous comment