List of usage examples for org.apache.poi.hssf.eventusermodel FormatTrackingHSSFListener FormatTrackingHSSFListener
public FormatTrackingHSSFListener(HSSFListener childListener, Locale locale)
From source file:com.jkoolcloud.tnt4j.streams.inputs.ExcelSXSSFRowStream.java
License:Apache License
/** * Reads HSSF (XLS) format excel file using Apache POI streaming SXSSF API. * * @param xlsFile//from w ww .java 2 s .c o m * excel HSSF format file to read * * @throws IOException * if excel file or workbook can't be read */ protected void readXLS(File xlsFile) throws IOException { NPOIFSFileSystem fs = null; InputStream dis = null; boolean passwordSet = false; try { fs = new NPOIFSFileSystem(xlsFile, true); DirectoryNode root = fs.getRoot(); if (root.hasEntry("EncryptedPackage")) { // NON-NLS dis = DocumentFactoryHelper.getDecryptedStream(fs, wbPass); } else { if (wbPass != null) { Biff8EncryptionKey.setCurrentUserPassword(wbPass); passwordSet = true; } dis = fs.createDocumentInputStream("Workbook"); // NON-NLS } HSSFRequest req = new HSSFRequest(); XLSEventListener listener = new XLSEventListener(this); FormatTrackingHSSFListener formatsListener = new FormatTrackingHSSFListener(listener, Locale.getDefault()); listener.setFormatListener(formatsListener); req.addListenerForAllRecords(formatsListener); HSSFEventFactory factory = new HSSFEventFactory(); factory.processEvents(req, dis); } finally { if (passwordSet) { Biff8EncryptionKey.setCurrentUserPassword((String) null); } Utils.close(fs); Utils.close(dis); } }
From source file:org.jberet.support.io.ExcelEventItemReader.java
License:Open Source License
@Override protected void initWorkbookAndSheet(final int startRowNumber) throws Exception { queue = new ArrayBlockingQueue<Object>(queueCapacity == 0 ? MAX_WORKSHEET_ROWS : queueCapacity); final POIFSFileSystem poifs = new POIFSFileSystem(inputStream); // get the Workbook (excel part) stream in a InputStream documentInputStream = poifs.createDocumentInputStream("Workbook"); final HSSFRequest req = new HSSFRequest(); final MissingRecordAwareHSSFListener missingRecordAwareHSSFListener = new MissingRecordAwareHSSFListener( new HSSFListenerImpl(this)); /*/* ww w. j av a 2 s .c o m*/ * Need to use English locale her because Jackson double parsing might break in certain regions * where ',' is used as decimal separator instead of '.'. */ formatListener = new FormatTrackingHSSFListener(missingRecordAwareHSSFListener, Locale.ENGLISH); req.addListenerForAllRecords(formatListener); final HSSFEventFactory factory = new HSSFEventFactory(); if (objectMapper == null) { initJsonFactoryAndObjectMapper(); } new Thread(new Runnable() { @Override public void run() { try { factory.processEvents(req, documentInputStream); } catch (final ReadCompletedException e) { SupportLogger.LOGGER.tracef("Completed reading %s%n", resource); } } }).start(); }