List of usage examples for org.apache.poi.xssf.eventusermodel XSSFReader getStylesTable
public StylesTable getStylesTable() throws IOException, InvalidFormatException
From source file:org.talend.dataprep.schema.xls.streaming.StreamingWorkbookReader.java
License:Open Source License
public void init(File f) { try {//from ww w .j a v a 2 s . c om if (builder.getPassword() != null) { // Based on: https://poi.apache.org/encryption.html POIFSFileSystem poifs = new POIFSFileSystem(f); EncryptionInfo info = new EncryptionInfo(poifs); Decryptor d = Decryptor.getInstance(info); d.verifyPassword(builder.getPassword()); pkg = OPCPackage.open(d.getDataStream(poifs)); } else { pkg = OPCPackage.open(f); } XSSFReader reader = new XSSFReader(pkg); SharedStringsTable sst = reader.getSharedStringsTable(); StylesTable styles = reader.getStylesTable(); loadSheets(reader, sst, styles, builder.getRowCacheSize()); } catch (IOException e) { throw new OpenException("Failed to open file", e); } catch (OpenXML4JException | XMLStreamException e) { throw new ReadException("Unable to read workbook", e); } catch (GeneralSecurityException e) { throw new ReadException("Unable to read workbook - Decryption failed", e); } }
From source file:sailpoint.services.task.genericImport.ExcelSaxImport.java
License:Apache License
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException/*ww w . j a v a 2s. co m*/ * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public void process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { OPCPackage xlsxPackage = OPCPackage.open(xlFile.getPath(), PackageAccess.READ); ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(xlsxPackage); XSSFReader xssfReader = new XSSFReader(xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { InputStream stream = iter.next(); if (sheetName.equals(iter.getSheetName()) || sheetName == null) { if (log.isDebugEnabled()) log.debug("Sheet name: " + sheetName + " (" + index + ")"); processSheet(styles, strings, stream); } stream.close(); ++index; } xlsxPackage.close(); }
From source file:service.ReadExcelFile.java
/** * Initiates the processing of the XLS workbook file to CSV. * //from www . ja v a 2s.c o m * @throws IOException * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public void process(int sheetNo) throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { InputStream stream = iter.next(); if (index == sheetNo) { // String sheetName = iter.getSheetName(); processSheet(styles, strings, stream); } stream.close(); ++index; } }
From source file:xlsconv.XLSX2CSV.java
License:Apache License
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException/*from w w w. j a va 2 s. c o m*/ * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public void process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { InputStream stream = iter.next(); String sheetName = iter.getSheetName(); // Output to separate files as well... if (writer != null) { writer.close(); } writer = new PrintStream(inputFile + "_" + sheetName + "_sheet-" + index + ".csv"); processSheet(styles, strings, stream); stream.close(); writer.close(); ++index; } }