52 * ensure it outputs all columns and rows.
53 *
54 * @author Nick Burch
55 */
56public class XLS2CSV implements HSSFListener {
57 private int minColumns;
58 private POIFSFileSystem fs;
59 private PrintStream output;
60
61 private int lastRowNumber;
62 private int lastColumnNumber;
63
64 /** *//** Should we output the formula, or the value it has */
65 private boolean outputFormulaValues = true;
66
67 /** *//** For parsing Formulas */
68 private SheetRecordCollectingListener workbookBuildingListener;
69 private HSSFWorkbook stubWorkbook;
70
71 // Records we pick up as we process
72 private SSTRecord sstRecord;
73 private FormatTrackingHSSFListener formatListener;
74
75 /** *//** So we known which sheet were on */
76 private int sheetIndex = -1;
77 private BoundSheetRecord[] orderedBSRs;
78 private ArrayList boundSheetRecords = new ArrayList();
79
80 // For handling formulas with string results
81 private int nextRow;
82 private int nextColumn;
83 private boolean outputNextStringRecord;
85 private final String OUTPUT_CHARSET = "GBK";
86
87 /** *//**
88 * Creates a new XLS -> CSV converter
89 *
90 * @param fs
91 * The POIFSFileSystem to process
92 * @param output
93 * The PrintStream to output the CSV to
94 * @param minColumns
95 * The minimum number of columns to output, or -1 for no minimum
96 */
97 public XLS2CSV(POIFSFileSystem fs, PrintStream output, int minColumns) {
98 this.fs = fs;
99 this.output = output;
100 this.minColumns = minColumns;
101 }
102
103 public XLS2CSV(String inputFilePath, String outputFilePath) throws Exception {
104 fs = new POIFSFileSystem(new FileInputStream(inputFilePath));
105 output = new PrintStream(outputFilePath, OUTPUT_CHARSET);
106 minColumns = -1;
107 }
108
109 /** *//**
110 * Creates a new XLS -> CSV converter
111 *
112 * @param filename
113 * The file to process
114 * @param minColumns
115 * The minimum number of columns to output, or -1 for no minimum
116 * @t