You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by phoenixhawke <Br...@intellidata.net> on 2012/03/09 19:17:04 UTC

POI XSSF Event Model - Get data from specified sheet

I'm trying to snag some data from a specific sheet in an xls document.  The
code below does not work - in printing out the classes of the Record objects
I found that my two-sheet XLS file has the BoundSheetRecords right after one
another in the list.  Suggestions?

For now, to keep things simple, i'll just show code for a row counter that
I'm trying to build:


   public void process()
         throws IOException
   {
      MissingRecordAwareHSSFListener listener = new
MissingRecordAwareHSSFListener(this);
      formatListener = new FormatTrackingHSSFListener(listener);

      HSSFEventFactory factory = new HSSFEventFactory();
      HSSFRequest request = new HSSFRequest();

      request.addListenerForAllRecords(formatListener); 
//I have tried using addListener(listener, sid) but no records were returned

      factory.processWorkbookEvents(request, fs);
   }


   /*
    * (non-Javadoc)
    * @see
    *
org.apache.poi.hssf.eventusermodel.HSSFListener#processRecord(org.apache
    * .poi.hssf.record.Record)
    */
   public void processRecord(Record record)
   {
      System.out.println(record.getClass());
      switch(record.getSid())
      {
         case BoundSheetRecord.sid:
            BoundSheetRecord bsr = (BoundSheetRecord) record;
            if(bsr.getSheetname().equals(this.requestedSheetName))
            {
               this.reqestedSheetIsOpen = true;
            }
            else
            {
               this.reqestedSheetIsOpen = false;
            }
            break;

         default:
            break;
      }

      if(this.reqestedSheetIsOpen && record instanceof
LastCellOfRowDummyRecord)
      {
         rowCount++;
      }
   }


--
View this message in context: http://apache-poi.1045710.n5.nabble.com/POI-XSSF-Event-Model-Get-data-from-specified-sheet-tp5551357p5551357.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: POI XSSF Event Model - Get data from specified sheet

Posted by phoenixhawke <Br...@intellidata.net>.
Ok, nevermind.  I figured out my problem.  I realized I was testing for the
wrong condition - I needed the index of the BOFRecord, not the
BoundSheetRecord.

Sorry to bother!

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/POI-XSSF-Event-Model-Get-data-from-specified-sheet-tp5551357p5551438.html
Sent from the POI - User mailing list archive at Nabble.com.

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