XSSF and SAX

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

XSSF and SAX

Mahmood Naderan-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XSSF and SAX

Javen O'Neal-2
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" <[hidden email]>
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XSSF and SAX

Mahmood Naderan-2
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 <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XSSF and SAX

Javen O'Neal-2
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" <[hidden email]>
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XSSF and SAX

Mahmood Naderan-2
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 <[hidden email]> 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" <[hidden email]>
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XSSF and SAX

Javen O'Neal-2
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" <[hidden email]>
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 <[hidden email]> 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" <[hidden email]>
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: XSSF and SAX

Mahmood Naderan-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...