/** * Process this record ourselves, and then pass it on to our child listener */ @Override public void processRecord(Record record) { // Handle it ourselves processRecordInternally(record); // Now pass on to our child _childListener.processRecord(record); }
public InternalWorkbook getStubWorkbook() { return createStubWorkbook( getExternSheetRecords(), getBoundSheetRecords(), getSSTRecord() ); }
/** * Process this record ourselves, and then * pass it on to our child listener */ @Override public void processRecord(Record record) { // Handle it ourselves processRecordInternally(record); // Now pass on to our child childListener.processRecord(record); }
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; }
public void run() throws IOException { try (POIFSFileSystem fs = new POIFSFileSystem(new File(file), true); InputStream din = BiffViewer.getPOIFSInputStream(fs)) { HSSFRequest req = new HSSFRequest(); req.addListenerForAllRecords(System.out::println); HSSFEventFactory factory = new HSSFEventFactory(); factory.processEvents(req, din); } }
/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param fs a POIFS filesystem containing your workbook * * @throws IOException if the workbook contained errors */ public void processWorkbookEvents(HSSFRequest req, POIFSFileSystem fs) throws IOException { processWorkbookEvents(req, fs.getRoot()); }
/** * Returns the format string, eg $##.##, used by your cell * * @param cell the cell * * @return the format string */ public String getFormatString(CellValueRecordInterface cell) { int formatIndex = getFormatIndex(cell); if (formatIndex == -1) { // Not found return null; } return getFormatString(formatIndex); }
/** * This is the equivalent of calling addListener(myListener, sid) for EVERY * record in the org.apache.poi.hssf.record package. This is for lazy * people like me. You can call this more than once with more than one listener, but * that seems like a bad thing to do from a practice-perspective unless you have a * compelling reason to do so (like maybe you send the event two places or log it or * something?). * * @param lsnr a single listener to associate with ALL records */ public void addListenerForAllRecords(HSSFListener lsnr) { short[] rectypes = RecordFactory.getAllKnownRecordSIDs(); for (short rectype : rectypes) { addListener(lsnr, rectype); } }
/** * Processes a DocumentInputStream into essentially Record events. * * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String) * @param req an Instance of HSSFRequest which has your registered listeners * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object * @return numeric user-specified result code. * * @throws HSSFUserException if the processing should be aborted */ public short abortableProcessEvents(HSSFRequest req, InputStream in) throws HSSFUserException { return genericProcessEvents(req, in); }
/** * Creates a stub workbook from the supplied records, * suitable for use with the {@link HSSFFormulaParser} * @param externs The ExternSheetRecords in your file * @param bounds The BoundSheetRecords in your file * @return A stub Workbook suitable for use with {@link HSSFFormulaParser} */ public static InternalWorkbook createStubWorkbook(ExternSheetRecord[] externs, BoundSheetRecord[] bounds) { return createStubWorkbook(externs, bounds, null); }
/** * Constructs a new MissingRecordAwareHSSFListener, which * will fire processRecord on the supplied child * HSSFListener for all Records, and missing records. * @param listener The HSSFListener to pass records on to */ public MissingRecordAwareHSSFListener(HSSFListener listener) { resetCounts(); childListener = listener; }
/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param fs a POIFS filesystem containing your workbook * @return numeric user-specified result code. * * @throws HSSFUserException if the processing should be aborted * @throws IOException if the workbook contained errors */ public short abortableProcessWorkbookEvents(HSSFRequest req, POIFSFileSystem fs) throws IOException, HSSFUserException { return abortableProcessWorkbookEvents(req, fs.getRoot()); }
/** * Processes a file into essentially record events. * * @param req an Instance of HSSFRequest which has your registered listeners * @param dir a DirectoryNode containing your workbook * @return numeric user-specified result code. * * @throws HSSFUserException if the processing should be aborted * @throws IOException if the workbook contained errors */ public short abortableProcessWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOException, HSSFUserException { InputStream in = dir.createDocumentInputStream("Workbook"); try { return abortableProcessEvents(req, in); } finally { in.close(); } }
break; userCode = req.processRecord(r); if (userCode != 0) { break;
public HSSFWorkbook getStubHSSFWorkbook() { // Create a base workbook HSSFWorkbook wb = HSSFWorkbook.create(getStubWorkbook()); // Stub the sheets, so sheet name lookups work for (BoundSheetRecord bsr : boundSheetRecords) { wb.createSheet(bsr.getSheetname()); } // Ready for Formula use! return wb; } public InternalWorkbook getStubWorkbook() {
/** * 读取 * * @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; } // ------------------------------------------------------------------------------ Read end
/** * Processes a DocumentInputStream into essentially Record events. * * If an <code>AbortableHSSFListener</code> causes a halt to processing during this call * the method will return just as with <code>abortableProcessEvents</code>, but no * user code or <code>HSSFUserException</code> will be passed back. * * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String) * @param req an Instance of HSSFRequest which has your registered listeners * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object */ public void processEvents(HSSFRequest req, InputStream in) { try { genericProcessEvents(req, in); } catch (HSSFUserException hue) { /*If an HSSFUserException user exception is thrown, ignore it.*/ } }
/** * 读取 * * @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; } // ------------------------------------------------------------------------------ Read end
@Override public DataOut streamParse( final InputStream is, final DataOut dout) throws Exception { _dout = dout; _firstRow = true; try { _fs = new POIFSFileSystem(is); MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(this); _formatListener = new FormatTrackingHSSFListener(listener); HSSFEventFactory factory = new HSSFEventFactory(); HSSFRequest request = new HSSFRequest(); request.addListenerForAllRecords(_formatListener); factory.processWorkbookEvents(request, _fs); } finally { try { is.close(); } catch (IOException e) { } } return dout; }
@Override public void execute() { init(); 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 EventWorkbookBuilder.SheetRecordCollectingListener(formatListener); request.addListenerForAllRecords(workbookBuildingListener); } try { factory.processWorkbookEvents(request, fs); } catch (IOException e) { throw new ExcelAnalysisException(e); } }