Java Mailing List Archive

http://www.java2.5341.com/

Home » user.poi »

Order of sheets returned by sheets.next()

Dobson, Paul L CTR USAF AFMC 416 SCMS/OBN

2008-09-26

Replies: Find Java Web Hosting

Author LoginPost Reply
I am using POI 3.5.1 beta to process excel files. First I get the names
of the sheets by parsing the workbook.xml file . I then use something
close to the code below to determine which sheets I want to process.
Problem is, the order returned by sheets.hasNext() doesn't seem to match
the order the sheets are in the workbook.xml file. How can I determine
which order the sheets.hasNext() will give me sheets to work with? Or,
is there a better way to selectively process sheets based on the sheet
title?



Thanks in advance for any suggestions.





String[] sheetNames = {"sheet1", "sheet2", "sheet3"};//this is actually
pulled from the workbook.xml using Sax.

Package pkg = Package.open(filePath);

XSSFReader r = new XSSFReader(pkg);

SharedStringsTable sst = r.getSharedStringsTable();

Iterator<InputStream> sheets = r.getSheetsData();

for (int x = 0; sheets.hasNext(); x++) {

          InputStream sheet = sheets.next();

if(sheetNames[x].equals("sheet2"))

          {

                    // parser sheet here.

                    //Sheet data that I parse is not the
data for "sheet 2"

          }

}



Thanks.

Paul Dobson

©2008 java2.5341.com - Jax Systems, LLC, U.S.A.