public class XLSX2CSV extends Object
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 XSSFEventBasedExcelExtractor
and XSSFSheetXMLHandler. Note that for many cases,
it may be possible to simply use those with a custom
XSSFSheetXMLHandler.SheetContentsHandler and no SAX code needed of
your own!
| Constructor and Description |
|---|
XLSX2CSV(OPCPackage pkg,
PrintStream output,
int minColumns)
Creates a new XLSX -> CSV converter
|
| Modifier and Type | Method and Description |
|---|---|
static void |
main(String[] args) |
void |
process()
Initiates the processing of the XLS workbook file to CSV.
|
void |
processSheet(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.
|
public XLSX2CSV(OPCPackage pkg, PrintStream output, int minColumns)
pkg - The XLSX package to processoutput - The PrintStream to output the CSV tominColumns - The minimum number of columns to output, or -1 for no minimumpublic void processSheet(Styles styles, SharedStrings strings, XSSFSheetXMLHandler.SheetContentsHandler sheetHandler, InputStream sheetInputStream) throws IOException, SAXException
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.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.public void process()
throws IOException,
OpenXML4JException,
SAXException
IOException - If reading the data from the package fails.SAXException - if parsing the XML data fails.OpenXML4JException