Class XLSX2CSV
- java.lang.Object
-
- org.apache.poi.examples.xssf.eventusermodel.XLSX2CSV
-
public class XLSX2CSV extends Object
A rudimentary XLSX -> CSV processor modeled on the POI sample program XLS2CSVmra from the package org.apache.poi.hssf.eventusermodel.examples. As with the HSSF version, this tries to spot missing rows and cells, and output empty entries for them.Data sheets are read using a SAX parser to keep the memory footprint relatively small, so this should be able to read enormous workbooks. The styles table and the shared-string table must be kept in memory. The standard POI styles table class is used, but a custom (read-only) class is used for the shared string table because the standard POI SharedStringsTable grows very quickly with the number of unique strings.
For a more advanced implementation of SAX event parsing of XLSX files, see
XSSFEventBasedExcelExtractorandXSSFSheetXMLHandler. Note that for many cases, it may be possible to simply use those with a customXSSFSheetXMLHandler.SheetContentsHandlerand no SAX code needed of your own!
-
-
Constructor Summary
Constructors Constructor Description XLSX2CSV(OPCPackage pkg, PrintStream output, int minColumns)Creates a new XLSX -> CSV converter
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] args)voidprocess()Initiates the processing of the XLS workbook file to CSV.voidprocessSheet(Styles styles, SharedStrings strings, XSSFSheetXMLHandler.SheetContentsHandler sheetHandler, InputStream sheetInputStream)Parses and shows the content of one sheet using the specified styles and shared-strings tables.
-
-
-
Constructor Detail
-
XLSX2CSV
public XLSX2CSV(OPCPackage pkg, PrintStream output, int minColumns)
Creates a new XLSX -> CSV converter- Parameters:
pkg- The XLSX package to processoutput- The PrintStream to output the CSV tominColumns- The minimum number of columns to output, or -1 for no minimum
-
-
Method Detail
-
processSheet
public void processSheet(Styles styles, SharedStrings strings, XSSFSheetXMLHandler.SheetContentsHandler sheetHandler, InputStream sheetInputStream) throws IOException, SAXException
Parses and shows the content of one sheet using the specified styles and shared-strings tables.- Parameters:
styles- The table of styles that may be referenced by cells in the sheetstrings- The table of strings that may be referenced by cells in the sheetsheetInputStream- The stream to read the sheet-data from.- Throws:
IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.SAXException- if parsing the XML data fails.
-
process
public void process() throws IOException, OpenXML4JException, SAXExceptionInitiates the processing of the XLS workbook file to CSV.- Throws:
IOException- If reading the data from the package fails.SAXException- if parsing the XML data fails.OpenXML4JException
-
-