You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Mahmood Naderan <nt...@yahoo.com.INVALID> on 2017/05/04 19:22:34 UTC

XSSF and SAX

Hi,
I read the document http://poi.apache.org/spreadsheet/how-to.html#sxssf in order to read a large excel file. The example in that section left me with some questions.

I want to read the cells row by row, so I expect to see/write a nested loop for that. The code for reading one sheet is

public void processOneSheet(String filename) throws Exception {
   OPCPackage pkg = OPCPackage.open(filename);
  		XSSFReader r = new XSSFReader( pkg );
  		SharedStringsTable sst = r.getSharedStringsTable();

   XMLReader parser = fetchSheetParser(sst);

  		// To look up the Sheet Name / Sheet Order / rID,
  		//  you need to process the core Workbook stream.
  		// Normally it's of the form rId# or rSheet#
  		InputStream sheet2 = r.getSheet("rId2");
  		InputSource sheetSource = new InputSource(sheet2);
  		parser.parse(sheetSource);
  		sheet2.close();
}



As you can see, there is no such thing here. It is stated in the document that the reader should be familiar with xml structure. I am not unfortunately... What is the outcome of parse()?




Thanks for any feedback. 
Regards,
Mahmood

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


Re: XSSF and SAX

Posted by Mahmood Naderan <nt...@yahoo.com.INVALID>.
Yes I read but didn't get the point.
Anyway, I decided to use Python package Openpyxl. I simply wrote a script for that and execute the python script via java. Although, it may look complicated with process overhead, it is indeed fast.

 
Regards,
Mahmood

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


Re: XSSF and SAX

Posted by Javen O'Neal <on...@apache.org>.
Define that function and put your business logic in it.

You said that you needed to for loop over the rows and cells. This is where
you do that.

Did you take a look at the XLSX2CSV example that I sent you?


On May 5, 2017 12:23 AM, "Mahmood Naderan" <nt...@yahoo.com.invalid>
wrote:

So what should I do to fix that? The code doesn't compile... Please see the
screen shot at


https://i.stack.imgur.com/axyDr.jpg



Regards,
Mahmood


On Friday, May 5, 2017 10:50 AM, Javen O'Neal <on...@apache.org> wrote:



It's an interface. You have to define how to proceed the sheet to meet the
needs of your application.


On May 4, 2017 10:21 PM, "Mahmood Naderan" <nt...@yahoo.com.invalid>
wrote:

> OK.
>
> When I write the code, I get an error that fetchSheetParser() is
> undefined. Although I imported the same libraries as document, I don't
know
> why I get that error.
>
> Which package contains that method?
>
>
> Regards,
> Mahmood
>
>
> On Friday, May 5, 2017 1:22 AM, Javen O'Neal <on...@apache.org> wrote:
>
>
>
> Take a look at
> https://svn.apache.org/repos/asf/poi/trunk/src/examples/
> src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

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

Re: XSSF and SAX

Posted by Mahmood Naderan <nt...@yahoo.com.INVALID>.
So what should I do to fix that? The code doesn't compile... Please see the screen shot at 


https://i.stack.imgur.com/axyDr.jpg


 
Regards,
Mahmood


On Friday, May 5, 2017 10:50 AM, Javen O'Neal <on...@apache.org> wrote:



It's an interface. You have to define how to proceed the sheet to meet the
needs of your application.


On May 4, 2017 10:21 PM, "Mahmood Naderan" <nt...@yahoo.com.invalid>
wrote:

> OK.
>
> When I write the code, I get an error that fetchSheetParser() is
> undefined. Although I imported the same libraries as document, I don't know
> why I get that error.
>
> Which package contains that method?
>
>
> Regards,
> Mahmood
>
>
> On Friday, May 5, 2017 1:22 AM, Javen O'Neal <on...@apache.org> wrote:
>
>
>
> Take a look at
> https://svn.apache.org/repos/asf/poi/trunk/src/examples/
> src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

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


Re: XSSF and SAX

Posted by Javen O'Neal <on...@apache.org>.
It's an interface. You have to define how to proceed the sheet to meet the
needs of your application.

On May 4, 2017 10:21 PM, "Mahmood Naderan" <nt...@yahoo.com.invalid>
wrote:

> OK.
>
> When I write the code, I get an error that fetchSheetParser() is
> undefined. Although I imported the same libraries as document, I don't know
> why I get that error.
>
> Which package contains that method?
>
>
> Regards,
> Mahmood
>
>
> On Friday, May 5, 2017 1:22 AM, Javen O'Neal <on...@apache.org> wrote:
>
>
>
> Take a look at
> https://svn.apache.org/repos/asf/poi/trunk/src/examples/
> src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: XSSF and SAX

Posted by Mahmood Naderan <nt...@yahoo.com.INVALID>.
OK. 

When I write the code, I get an error that fetchSheetParser() is undefined. Although I imported the same libraries as document, I don't know why I get that error.

Which package contains that method?

 
Regards,
Mahmood


On Friday, May 5, 2017 1:22 AM, Javen O'Neal <on...@apache.org> wrote:



Take a look at
https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java

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


Re: XSSF and SAX

Posted by Javen O'Neal <on...@apache.org>.
Take a look at
https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java

On May 4, 2017 12:22 PM, "Mahmood Naderan" <nt...@yahoo.com.invalid>
wrote:

> Hi,
> I read the document http://poi.apache.org/spreadsheet/how-to.html#sxssf
> in order to read a large excel file. The example in that section left me
> with some questions.
>
> I want to read the cells row by row, so I expect to see/write a nested
> loop for that. The code for reading one sheet is
>
> public void processOneSheet(String filename) throws Exception {
>    OPCPackage pkg = OPCPackage.open(filename);
>                 XSSFReader r = new XSSFReader( pkg );
>                 SharedStringsTable sst = r.getSharedStringsTable();
>
>    XMLReader parser = fetchSheetParser(sst);
>
>                 // To look up the Sheet Name / Sheet Order / rID,
>                 //  you need to process the core Workbook stream.
>                 // Normally it's of the form rId# or rSheet#
>                 InputStream sheet2 = r.getSheet("rId2");
>                 InputSource sheetSource = new InputSource(sheet2);
>                 parser.parse(sheetSource);
>                 sheet2.close();
> }
>
>
>
> As you can see, there is no such thing here. It is stated in the document
> that the reader should be familiar with xml structure. I am not
> unfortunately... What is the outcome of parse()?
>
>
>
>
> Thanks for any feedback.
> Regards,
> Mahmood
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>