Example usage for org.apache.poi.hssf.eventusermodel HSSFEventFactory abortableProcessWorkbookEvents

List of usage examples for org.apache.poi.hssf.eventusermodel HSSFEventFactory abortableProcessWorkbookEvents

Introduction

In this page you can find the example usage for org.apache.poi.hssf.eventusermodel HSSFEventFactory abortableProcessWorkbookEvents.

Prototype

public short abortableProcessWorkbookEvents(HSSFRequest req, DirectoryNode dir)
        throws IOException, HSSFUserException 

Source Link

Document

Processes a file into essentially record events.

Usage

From source file:com.bayareasoftware.chartengine.ds.util.XLS2Data.java

License:Apache License

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

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

    if (outputFormulaValues) {
        request.addListenerForAllRecords(formatListener);
    } else {//from   w w  w .  ja va  2s  .  com
        workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }
    try {
        // we can handle this when we only want to read a particular sheet
        // and use this exception when we've moved beyond that sheet
        factory.abortableProcessWorkbookEvents(request, fs);
    } catch (HSSFUserException hssue) {
        hssue.printStackTrace();
    } catch (MaxRowsReachedException re) {
        System.out.println("aborted? " + re);
    }
    // make sure we got the last sheet
    if (currentSheetName != null && sheet2data.get(currentSheetName) == null) {
        sheet2data.put(currentSheetName, currentData);
    }
    //factory.processWorkbookEvents(request, fs);        
}

From source file:com.netxforge.netxstudio.screens.f4.support.XLSService.java

License:Open Source License

public int go(IProgressMonitor monitor, FileInputStream fin) throws IOException {
    reset();/*from w  w  w  .j  av  a  2 s.  com*/
    this.currentMonitor = monitor;
    monitor.subTask("POI Ongoing");

    // TODO, we would need to do a first evaluation of the workbook to get
    // an idea of the amount of work we can expect here.
    // For now increment worked, for each single row.

    formatTrackingListener = new FormatTrackingHSSFListener(this);

    // create a new file input stream with the input file specified
    // at the command line
    // create a new org.apache.poi.poifs.filesystem.Filesystem
    POIFSFileSystem poifs = new POIFSFileSystem(fin);

    // get the Workbook (excel part) stream in a InputStream
    // InputStream din = poifs.createDocumentInputStream("Workbook");

    // construct out HSSFRequest object
    HSSFRequest req = new HSSFRequest();
    // lazy listen for ALL records with the listener shown above
    req.addListenerForAllRecords(formatTrackingListener);
    // create our event factory
    HSSFEventFactory factory = new HSSFEventFactory();
    // process our events based on the document input stream
    try {
        factory.abortableProcessWorkbookEvents(req, poifs);
    } catch (Exception e) {
        // We have an issue or cancel.
        System.out.println(e.getMessage());
    } finally {
        // once all the events are processed close our file input stream
        fin.close();
        // and our document input stream (don't want to leak these!)
        // din.close();
    }
    // TODO, silent return, could also be an exception with information on
    // what went wrong.
    return currentReturnCode;
}