Example usage for org.apache.poi.xssf.streaming SXSSFSheet SXSSFSheet

List of usage examples for org.apache.poi.xssf.streaming SXSSFSheet SXSSFSheet

Introduction

In this page you can find the example usage for org.apache.poi.xssf.streaming SXSSFSheet SXSSFSheet.

Prototype

public SXSSFSheet(SXSSFWorkbook workbook, XSSFSheet xSheet) throws IOException 

Source Link

Usage

From source file:com.jkoolcloud.tnt4j.streams.inputs.ExcelSXSSFRowStream.java

License:Apache License

/**
 * Reads XSSF (XLXS) format excel file using Apache POI streaming SXSSF API.
 *
 * @param xlsxFile/*from  w  ww  .j a  va 2s. co m*/
 *            excel XSSF format file to read
 *
 * @throws IOException
 *             if excel file or workbook can't be read
 * @throws SAXException
 *             if file contained XML reading fails
 * @throws OpenXML4JException
 *             if file contained XML reading fails
 */
protected void readXLXS(File xlsxFile) throws IOException, SAXException, OpenXML4JException {
    try (OPCPackage xlsxPackage = OPCPackage.open(xlsxFile, PackageAccess.READ)) {
        ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(xlsxPackage);
        XSSFReader xssfReader = new XSSFReader(xlsxPackage);
        StylesTable styles = xssfReader.getStylesTable();
        XSSFReader.SheetIterator sIter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        while (sIter.hasNext()) {
            try (InputStream sStream = sIter.next()) {
                String sheetName = sIter.getSheetName();
                boolean match = sheetNameMatcher == null || sheetNameMatcher.matcher(sheetName).matches();
                if (!match) {
                    continue;
                }

                SXSSFSheet sheet = new SXSSFSheet(new SXSSFWorkbook(), null);
                processSXSSFSheet(styles, strings, new XLSXSheetContentHandler(this, sheet), sStream);
            }
        }
    }
}