Search in sources :

Example 1 with HSSFRequest

use of org.apache.poi.hssf.eventusermodel.HSSFRequest in project poi by apache.

the class EventBasedExcelExtractor method triggerExtraction.

private TextListener triggerExtraction() throws IOException {
    TextListener tl = new TextListener();
    FormatTrackingHSSFListener ft = new FormatTrackingHSSFListener(tl);
    tl._ft = ft;
    // Register and process
    HSSFEventFactory factory = new HSSFEventFactory();
    HSSFRequest request = new HSSFRequest();
    request.addListenerForAllRecords(ft);
    factory.processWorkbookEvents(request, _dir);
    return tl;
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) FormatTrackingHSSFListener(org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener)

Example 2 with HSSFRequest

use of org.apache.poi.hssf.eventusermodel.HSSFRequest in project poi by apache.

the class TestAbortableListener method testAbortingBasics.

public void testAbortingBasics() throws Exception {
    AbortableCountingListener l = new AbortableCountingListener(1000);
    HSSFRequest req = new HSSFRequest();
    req.addListenerForAllRecords(l);
    HSSFEventFactory f = new HSSFEventFactory();
    assertEquals(0, l.countSeen);
    assertEquals(null, l.lastRecordSeen);
    POIFSFileSystem fs = openSample();
    short res = f.abortableProcessWorkbookEvents(req, fs);
    assertEquals(0, res);
    assertEquals(175, l.countSeen);
    assertEquals(EOFRecord.sid, l.lastRecordSeen.getSid());
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest)

Example 3 with HSSFRequest

use of org.apache.poi.hssf.eventusermodel.HSSFRequest in project poi by apache.

the class TestChartTitleFormatRecord method testRecord.

@Test
public void testRecord() throws Exception {
    NPOIFSFileSystem fs = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithFormattedGraphTitle.xls"));
    // Check we can open the file via usermodel
    HSSFWorkbook hssf = new HSSFWorkbook(fs);
    // Now process it through eventusermodel, and
    //  look out for the title records
    ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
    InputStream din = fs.createDocumentInputStream("Workbook");
    HSSFRequest req = new HSSFRequest();
    req.addListenerForAllRecords(grabber);
    HSSFEventFactory factory = new HSSFEventFactory();
    factory.processEvents(req, din);
    din.close();
    // Should've found one
    assertEquals(1, grabber.chartTitleFormatRecords.size());
    // And it should be of something interesting
    ChartTitleFormatRecord r = grabber.chartTitleFormatRecords.get(0);
    assertEquals(3, r.getFormatCount());
    hssf.close();
    fs.close();
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) InputStream(java.io.InputStream) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 4 with HSSFRequest

use of org.apache.poi.hssf.eventusermodel.HSSFRequest 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 5 with HSSFRequest

use of org.apache.poi.hssf.eventusermodel.HSSFRequest 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)

Aggregations

HSSFEventFactory (org.apache.poi.hssf.eventusermodel.HSSFEventFactory)9 HSSFRequest (org.apache.poi.hssf.eventusermodel.HSSFRequest)9 FormatTrackingHSSFListener (org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener)4 InputStream (java.io.InputStream)3 SheetRecordCollectingListener (org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener)3 MissingRecordAwareHSSFListener (org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)2 POIException (cn.hutool.poi.exceptions.POIException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HSSFListener (org.apache.poi.hssf.eventusermodel.HSSFListener)1 Record (org.apache.poi.hssf.record.Record)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 Test (org.junit.Test)1