Search in sources :

Example 1 with SheetRecordCollectingListener

use of org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener in project hutool by looly.

the class Excel03SaxReader method read.

/**
 * 读取
 *
 * @param fs {@link POIFSFileSystem}
 * @param sheetIndex sheet序号
 * @return this
 * @throws POIException IO异常包装
 */
public Excel03SaxReader read(POIFSFileSystem fs, int sheetIndex) throws POIException {
    this.sheetIndex = sheetIndex;
    formatListener = new FormatTrackingHSSFListener(new MissingRecordAwareHSSFListener(this));
    final HSSFRequest request = new HSSFRequest();
    if (isOutputFormulaValues) {
        request.addListenerForAllRecords(formatListener);
    } else {
        workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }
    final HSSFEventFactory factory = new HSSFEventFactory();
    try {
        factory.processWorkbookEvents(request, fs);
    } catch (IOException e) {
        throw new POIException(e);
    }
    return this;
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) SheetRecordCollectingListener(org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener) MissingRecordAwareHSSFListener(org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) IOException(java.io.IOException) FormatTrackingHSSFListener(org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener) POIException(cn.hutool.poi.exceptions.POIException)

Example 2 with SheetRecordCollectingListener

use of org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener in project jeesuite-libs by vakinge.

the class XLS2CSV method process.

/**
 * Initiates the processing of the XLS file to CSV
 */
public List<String> 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 {
        workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }
    factory.processWorkbookEvents(request, fs);
    return results;
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) SheetRecordCollectingListener(org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener) MissingRecordAwareHSSFListener(org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) FormatTrackingHSSFListener(org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener)

Example 3 with SheetRecordCollectingListener

use of org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener in project poi by apache.

the class XLS2CSVmra method process.

/**
	 * Initiates the processing of the XLS file to CSV
	 */
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 {
        workbookBuildingListener = new SheetRecordCollectingListener(formatListener);
        request.addListenerForAllRecords(workbookBuildingListener);
    }
    factory.processWorkbookEvents(request, fs);
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) SheetRecordCollectingListener(org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener) MissingRecordAwareHSSFListener(org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) FormatTrackingHSSFListener(org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener)

Example 4 with SheetRecordCollectingListener

use of org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener in project poi by apache.

the class TestEventWorkbookBuilder method setUp.

@Override
public void setUp() {
    HSSFRequest req = new HSSFRequest();
    mockListen = new MockHSSFListener();
    listener = new SheetRecordCollectingListener(mockListen);
    req.addListenerForAllRecords(listener);
    HSSFEventFactory factory = new HSSFEventFactory();
    try {
        InputStream is = HSSFTestDataSamples.openSampleFileStream("3dFormulas.xls");
        POIFSFileSystem fs = new POIFSFileSystem(is);
        factory.processWorkbookEvents(req, fs);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SheetRecordCollectingListener(org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener) InputStream(java.io.InputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) IOException(java.io.IOException)

Aggregations

SheetRecordCollectingListener (org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener)4 FormatTrackingHSSFListener (org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener)3 HSSFEventFactory (org.apache.poi.hssf.eventusermodel.HSSFEventFactory)3 HSSFRequest (org.apache.poi.hssf.eventusermodel.HSSFRequest)3 MissingRecordAwareHSSFListener (org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener)3 IOException (java.io.IOException)2 POIException (cn.hutool.poi.exceptions.POIException)1 InputStream (java.io.InputStream)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1