Discussion:
Is it POI error starting 3.14 version onwards
Syed Mudassir Ahmed
2018-05-15 07:19:33 UTC
Permalink
Hi,
I am trying to read data from a XLSX sheet via XSSFSheetXMLHandler. The
source code is below.

public static void main(String str[]) throws Exception {
String filePath
= "/home/gaian/Desktop/salary.xlsx";
File file = new File(filePath);
InputStream inputStream = new FileInputStream(file);
OPCPackage pkg = OPCPackage.open(inputStream);

SheetContentsHandler sheetContentsHandler = new
SheetContentsHandler() {
@Override
public void startRow(int rowIndex) {
}

@Override
public void endRow(int i) {
}

@Override
public void cell(String cell, String formattedValue,
XSSFComment c) {
System.out.println("cell encountered with addess:<" + cell
+ "> and value:<" + formattedValue + ">");
}

@Override
public void headerFooter(String text, boolean isHeader, String
tagName) {
System.out.println("headerFooter()");
}
};

ReadOnlySharedStringsTable strings = new
ReadOnlySharedStringsTable(pkg);
XSSFReader xssfReader = new XSSFReader(pkg);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator)
xssfReader.getSheetsData();
InputStream stream = worksheets.next();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader();

ContentHandler handler
= new XSSFSheetXMLHandler(styles, strings,
sheetContentsHandler, false);

sheetParser.setContentHandler(handler);
sheetParser.parse(new InputSource(stream));
}

When I use the POI version 3.13, I am getting the following output:

cell encountered with addess:<A1> and value:<Salary>
cell encountered with addess:<A2> and value:<99.965432>

The moment I switch to version 3.14 or higher, I am no longer getting any
output.

Can someone pls let me know if any more code changes needed if I switch
to 3.14 or higher? I even checked the test cases in Apache POI 3.17
sources but was shocked not to find any there. Any example/references that
I can go through pls? This is blocker for one of my applications.


Thanks,
Tim Allison
2018-05-15 10:13:36 UTC
Permalink
Any chanc you can share the file?

On Tue, May 15, 2018 at 3:19 AM Syed Mudassir Ahmed <
Post by Syed Mudassir Ahmed
Hi,
I am trying to read data from a XLSX sheet via XSSFSheetXMLHandler. The
source code is below.
public static void main(String str[]) throws Exception {
String filePath
= "/home/gaian/Desktop/salary.xlsx";
File file = new File(filePath);
InputStream inputStream = new FileInputStream(file);
OPCPackage pkg = OPCPackage.open(inputStream);
SheetContentsHandler sheetContentsHandler = new
SheetContentsHandler() {
@Override
public void startRow(int rowIndex) {
}
@Override
public void endRow(int i) {
}
@Override
public void cell(String cell, String formattedValue,
XSSFComment c) {
System.out.println("cell encountered with addess:<" + cell
+ "> and value:<" + formattedValue + ">");
}
@Override
public void headerFooter(String text, boolean isHeader, String
tagName) {
System.out.println("headerFooter()");
}
};
ReadOnlySharedStringsTable strings = new
ReadOnlySharedStringsTable(pkg);
XSSFReader xssfReader = new XSSFReader(pkg);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator)
xssfReader.getSheetsData();
InputStream stream = worksheets.next();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader();
ContentHandler handler
= new XSSFSheetXMLHandler(styles, strings,
sheetContentsHandler, false);
sheetParser.setContentHandler(handler);
sheetParser.parse(new InputSource(stream));
}
cell encountered with addess:<A1> and value:<Salary>
cell encountered with addess:<A2> and value:<99.965432>
The moment I switch to version 3.14 or higher, I am no longer getting
any output.
Can someone pls let me know if any more code changes needed if I switch
to 3.14 or higher? I even checked the test cases in Apache POI 3.17
sources but was shocked not to find any there. Any example/references that
I can go through pls? This is blocker for one of my applications.
Thanks,
Syed Mudassir Ahmed
2018-05-15 10:15:05 UTC
Permalink
Yes, pls find the file attached here.

Thanks,
Post by Tim Allison
Any chanc you can share the file?
On Tue, May 15, 2018 at 3:19 AM Syed Mudassir Ahmed <
Post by Syed Mudassir Ahmed
Hi,
I am trying to read data from a XLSX sheet via XSSFSheetXMLHandler.
The
Post by Syed Mudassir Ahmed
source code is below.
public static void main(String str[]) throws Exception {
String filePath
= "/home/gaian/Desktop/salary.xlsx";
File file = new File(filePath);
InputStream inputStream = new FileInputStream(file);
OPCPackage pkg = OPCPackage.open(inputStream);
SheetContentsHandler sheetContentsHandler = new
SheetContentsHandler() {
@Override
public void startRow(int rowIndex) {
}
@Override
public void endRow(int i) {
}
@Override
public void cell(String cell, String formattedValue,
XSSFComment c) {
System.out.println("cell encountered with addess:<" +
cell
Post by Syed Mudassir Ahmed
+ "> and value:<" + formattedValue + ">");
}
@Override
public void headerFooter(String text, boolean isHeader,
String
Post by Syed Mudassir Ahmed
tagName) {
System.out.println("headerFooter()");
}
};
ReadOnlySharedStringsTable strings = new
ReadOnlySharedStringsTable(pkg);
XSSFReader xssfReader = new XSSFReader(pkg);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator)
xssfReader.getSheetsData();
InputStream stream = worksheets.next();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
XMLReader sheetParser = saxFactory.newSAXParser().
getXMLReader();
Post by Syed Mudassir Ahmed
ContentHandler handler
= new XSSFSheetXMLHandler(styles, strings,
sheetContentsHandler, false);
sheetParser.setContentHandler(handler);
sheetParser.parse(new InputSource(stream));
}
cell encountered with addess:<A1> and value:<Salary>
cell encountered with addess:<A2> and value:<99.965432>
The moment I switch to version 3.14 or higher, I am no longer getting
any output.
Can someone pls let me know if any more code changes needed if I switch
to 3.14 or higher? I even checked the test cases in Apache POI 3.17
sources but was shocked not to find any there. Any example/references
that
Post by Syed Mudassir Ahmed
I can go through pls? This is blocker for one of my applications.
Thanks,
Syed Mudassir Ahmed
2018-05-16 05:31:32 UTC
Permalink
any update on this pls? This is blocking me.

Thanks,


On Tue, May 15, 2018 at 3:45 PM, Syed Mudassir Ahmed <
Post by Syed Mudassir Ahmed
Yes, pls find the file attached here.
Thanks,
Post by Tim Allison
Any chanc you can share the file?
On Tue, May 15, 2018 at 3:19 AM Syed Mudassir Ahmed <
Post by Syed Mudassir Ahmed
Hi,
I am trying to read data from a XLSX sheet via XSSFSheetXMLHandler.
The
Post by Syed Mudassir Ahmed
source code is below.
public static void main(String str[]) throws Exception {
String filePath
= "/home/gaian/Desktop/salary.xlsx";
File file = new File(filePath);
InputStream inputStream = new FileInputStream(file);
OPCPackage pkg = OPCPackage.open(inputStream);
SheetContentsHandler sheetContentsHandler = new
SheetContentsHandler() {
@Override
public void startRow(int rowIndex) {
}
@Override
public void endRow(int i) {
}
@Override
public void cell(String cell, String formattedValue,
XSSFComment c) {
System.out.println("cell encountered with addess:<" +
cell
Post by Syed Mudassir Ahmed
+ "> and value:<" + formattedValue + ">");
}
@Override
public void headerFooter(String text, boolean isHeader,
String
Post by Syed Mudassir Ahmed
tagName) {
System.out.println("headerFooter()");
}
};
ReadOnlySharedStringsTable strings = new
ReadOnlySharedStringsTable(pkg);
XSSFReader xssfReader = new XSSFReader(pkg);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator)
xssfReader.getSheetsData();
InputStream stream = worksheets.next();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
XMLReader sheetParser = saxFactory.newSAXParser().getX
MLReader();
Post by Syed Mudassir Ahmed
ContentHandler handler
= new XSSFSheetXMLHandler(styles, strings,
sheetContentsHandler, false);
sheetParser.setContentHandler(handler);
sheetParser.parse(new InputSource(stream));
}
cell encountered with addess:<A1> and value:<Salary>
cell encountered with addess:<A2> and value:<99.965432>
The moment I switch to version 3.14 or higher, I am no longer getting
any output.
Can someone pls let me know if any more code changes needed if I
switch
Post by Syed Mudassir Ahmed
to 3.14 or higher? I even checked the test cases in Apache POI 3.17
sources but was shocked not to find any there. Any example/references
that
Post by Syed Mudassir Ahmed
I can go through pls? This is blocker for one of my applications.
Thanks,
Tim Allison
2018-05-16 13:19:39 UTC
Permalink
You need to make your SAXReader namespace aware:

saxFactory.setNamespaceAware(true);
Sorry for my delay. I just tested your file with Apache Tika 1.18 which
<body><div><h1>Sheet1</h1>
<table><tbody><tr> <td>Salary</td></tr>
<tr> <td>99.965432</td></tr>
</tbody></table>
</div>
<div><h1>Sheet2</h1>
<table><tbody/></table>
</div>
<div><h1>Sheet3</h1>
<table><tbody/></table>
</div>
</body></html>
That's promising... Let me take a look at your example code.
Post by Syed Mudassir Ahmed
any update on this pls? This is blocking me.
Thanks,
On Tue, May 15, 2018 at 3:45 PM, Syed Mudassir Ahmed <
Post by Syed Mudassir Ahmed
Yes, pls find the file attached here.
Thanks,
Post by Tim Allison
Any chanc you can share the file?
On Tue, May 15, 2018 at 3:19 AM Syed Mudassir Ahmed <
Post by Syed Mudassir Ahmed
Hi,
I am trying to read data from a XLSX sheet via
XSSFSheetXMLHandler. The
Post by Syed Mudassir Ahmed
source code is below.
public static void main(String str[]) throws Exception {
String filePath
= "/home/gaian/Desktop/salary.xlsx";
File file = new File(filePath);
InputStream inputStream = new FileInputStream(file);
OPCPackage pkg = OPCPackage.open(inputStream);
SheetContentsHandler sheetContentsHandler = new
SheetContentsHandler() {
@Override
public void startRow(int rowIndex) {
}
@Override
public void endRow(int i) {
}
@Override
public void cell(String cell, String formattedValue,
XSSFComment c) {
System.out.println("cell encountered with addess:<" +
cell
Post by Syed Mudassir Ahmed
+ "> and value:<" + formattedValue + ">");
}
@Override
public void headerFooter(String text, boolean isHeader,
String
Post by Syed Mudassir Ahmed
tagName) {
System.out.println("headerFooter()");
}
};
ReadOnlySharedStringsTable strings = new
ReadOnlySharedStringsTable(pkg);
XSSFReader xssfReader = new XSSFReader(pkg);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator worksheets =
(XSSFReader.SheetIterator)
Post by Syed Mudassir Ahmed
xssfReader.getSheetsData();
InputStream stream = worksheets.next();
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
XMLReader sheetParser = saxFactory.newSAXParser().getX
MLReader();
Post by Syed Mudassir Ahmed
ContentHandler handler
= new XSSFSheetXMLHandler(styles, strings,
sheetContentsHandler, false);
sheetParser.setContentHandler(handler);
sheetParser.parse(new InputSource(stream));
}
cell encountered with addess:<A1> and value:<Salary>
cell encountered with addess:<A2> and value:<99.965432>
The moment I switch to version 3.14 or higher, I am no longer
getting
Post by Syed Mudassir Ahmed
any output.
Can someone pls let me know if any more code changes needed if I
switch
Post by Syed Mudassir Ahmed
to 3.14 or higher? I even checked the test cases in Apache POI 3.17
sources but was shocked not to find any there. Any
example/references that
Post by Syed Mudassir Ahmed
I can go through pls? This is blocker for one of my applications.
Thanks,
pj.fanning
2018-05-16 18:38:43 UTC
Permalink
https://github.com/apache/poi/blob/trunk/src/ooxml/java/org/apache/poi/util/SAXHelper.java

org.apache.poi.util.SAXHelper has a newXMLReader() method that creates an
XMLReader instance that satisfies the requirements for this use case.



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@poi.apache.org
For additional commands, e-mail: user-***@poi.apache.org

Loading...