List of usage examples for org.apache.poi.xssf.eventusermodel XSSFReader XSSFReader
public XSSFReader(OPCPackage pkg) throws IOException, OpenXML4JException
From source file:sailpoint.services.task.genericImport.ExcelSaxImport.java
License:Apache License
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException/*from ww w . j a va 2 s. c o 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. * /*ww w .j av a2 s. c om*/ * @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/* w ww .j ava 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; } }