Example usage for org.apache.poi.xssf.eventusermodel XSSFReader getSharedStringsData

List of usage examples for org.apache.poi.xssf.eventusermodel XSSFReader getSharedStringsData

Introduction

In this page you can find the example usage for org.apache.poi.xssf.eventusermodel XSSFReader getSharedStringsData.

Prototype

public InputStream getSharedStringsData() throws IOException, InvalidFormatException 

Source Link

Document

Returns an InputStream to read the contents of the shared strings table.

Usage

From source file:com.ostrichemulators.semtool.poi.main.LowMemXlsReader.java

private void populateSharedStrings(XSSFReader r) {

    try (InputStream is = r.getSharedStringsData()) {
        XMLReader parser = XMLReaderFactory.createXMLReader();
        ContentHandler handler = new XlsXmlBase(new ArrayList<>()) {
            int count = 0;

            @Override//from  www  .j  a va 2 s  .c o  m
            public void startDocument() throws SAXException {
                super.startDocument();
                count = 0;
            }

            @Override
            public void endDocument() throws SAXException {
                super.endDocument();
                log.debug(count + " strings cached");
            }

            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts)
                    throws SAXException {
                setReading("t".equals(localName));
                resetContents();
            }

            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {
                if (isReading()) {
                    sharedStrings.add(getContents());
                    setReading(false);
                    count++;
                }
            }
        };
        parser.setContentHandler(handler);
        parser.parse(new InputSource(is));
    } catch (Exception e) {
        log.error(e, e);
    }
}

From source file:ec.util.spreadsheet.poi.FastPoiBook.java

License:EUPL

private static ByteSource newSharedStringsDataSupplier(final XSSFReader reader) {
    return new ByteSource() {
        @Override//from  w  w w.jav  a  2s.c  o m
        public InputStream openStream() throws IOException {
            try {
                return reader.getSharedStringsData();
            } catch (InvalidFormatException ex) {
                throw new IOException(ex);
            }
        }
    };
}