Example usage for org.apache.poi.hssf.record RecordFactoryInputStream RecordFactoryInputStream

List of usage examples for org.apache.poi.hssf.record RecordFactoryInputStream RecordFactoryInputStream

Introduction

In this page you can find the example usage for org.apache.poi.hssf.record RecordFactoryInputStream RecordFactoryInputStream.

Prototype

public RecordFactoryInputStream(InputStream in, boolean shouldIncludeContinueRecords) 

Source Link

Usage

From source file:com.googlecode.sqlsheet.stream.XlsSheetIterator.java

License:Apache License

/**
 * Initiates the processing/*from   w ww  .  ja v a 2  s .  co  m*/
 * - position stream to the right sheet
 * - extracts columns
 * - extracts first row
 */
public void postConstruct() throws SQLException {
    try {
        boundSheetRecords = new ArrayList();
        sheetIndex = -1;
        inRequiredSheet = false;
        outputFormulaValues = true;

        fileSystem = new NPOIFSFileSystem(getFileName().openStream());
        recordStream = new RecordFactoryInputStream(fileSystem.getRoot().createDocumentInputStream("Workbook"),
                false);
        MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this);
        formatListener = new FormatTrackingHSSFListener(listener);
        requestPublic = new PublicMorozoffHSSFRequest();
        if (outputFormulaValues) {
            requestPublic.addListenerForAllRecords(formatListener);
        } else {
            workbookBuildingListener = new EventWorkbookBuilder.SheetRecordCollectingListener(formatListener);
            requestPublic.addListenerForAllRecords(workbookBuildingListener);
        }

        // Process each record as they come in till we get to the right sheet
        while (!inRequiredSheet) {
            Record r = recordStream.nextRecord();
            if (r == null) {
                break;
            }
            try {
                short userCode = requestPublic.processRecord(r);
                if (userCode != 0) {
                    break;
                }

            } catch (HSSFUserException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
        //Flush rows counter
        setCurrentSheetRowIndex(0L);
        //Fill current row
        processNextRecords();
    } catch (IOException e) {
        throw new SQLException(e.getMessage(), e);
    }

}