/** * Constructor * * @param w The workbook to interrogate * @param out The output stream to which the CSV values are written * @param encoding The encoding used by the output stream. Null or * unrecognized values cause the encoding to default to UTF8 * @exception java.io.IOException */ public Escher(Workbook w, TextWriter os, string encoding) { if (encoding == null || encoding == "UnicodeBig") { encoding = "UTF8"; } try { for (int i = 0; i < w.getNumberOfSheets(); i++) { SheetImpl s = (SheetImpl)w.getSheet(i); os.Write(s.getName()); os.WriteLine(); os.WriteLine(); DrawingData dd = s.getDrawingData(); if (dd != null) { EscherDisplay ed = new EscherDisplay(dd, os); ed.display(); } os.WriteLine(); os.WriteLine(); os.Flush(); } os.Flush(); } catch (Exception e) { Console.WriteLine(e); } }
/** * Constructor * * @param w The workbook to interrogate * @param out The output stream to which the CSV values are written * @param encoding The encoding used by the output stream. Null or * unrecognized values cause the encoding to default to UTF8 * @param hide Suppresses hidden cells * @exception java.io.IOException */ public CSV(Workbook w, TextWriter os, string encoding, bool hide) { if (encoding == null || encoding != "UnicodeBig") { encoding = "UTF8"; } try { //OutputStreamWriter osw = os; //BufferedWriter os = new BufferedWriter(osw); for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++) { Sheet s = w.getSheet(sheet); if (!(hide && s.getSettings().isHidden())) { os.Write("*** " + s.getName() + " ****"); os.WriteLine(); Cell[] row = null; for (int i = 0; i < s.getRows(); i++) { row = s.getRow(i); if (row.Length > 0) { if (!(hide && row[0].isHidden())) { os.Write(row[0].getContents()); // Java 1.4 code to handle embedded commas // os.Write("\"" + row[0].getContents().replaceAll("\"","\"\"") + "\""); } for (int j = 1; j < row.Length; j++) { os.Write(','); if (!(hide && row[j].isHidden())) { os.Write(row[j].getContents()); // Java 1.4 code to handle embedded quotes // os.Write("\"" + row[j].getContents().replaceAll("\"","\"\"") + "\""); } } } os.WriteLine(); } } } os.Flush(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
/** * Constructor * * @param w The workbook to interrogate * @param out The output stream to which the CSV values are written * @param encoding The encoding used by the output stream. Null or * unrecognized values cause the encoding to default to UTF8 * @exception java.io.IOException */ public Features(Workbook w, TextWriter os, string encoding) { if (encoding == null || encoding != "UnicodeBig") { encoding = "UTF8"; } try { //OutputStreamWriter osw = new OutputStreamWriter(out, encoding); //BufferedWriter os = new BufferedWriter(osw); for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++) { Sheet s = w.getSheet(sheet); os.Write(s.getName()); os.WriteLine(); Cell[] row = null; Cell c = null; for (int i = 0; i < s.getRows(); i++) { row = s.getRow(i); for (int j = 0; j < row.Length; j++) { c = row[j]; if (c.getCellFeatures() != null) { CellFeatures features = c.getCellFeatures(); StringBuilder sb = new StringBuilder(); CellReferenceHelper.getCellReference (c.getColumn(), c.getRow(), sb); os.Write("Cell " + sb.ToString() + " contents: " + c.getContents()); os.Flush(); os.Write(" comment: " + features.getComment()); os.Flush(); os.WriteLine(); } } } } os.Flush(); //os.close(); } catch (Exception e) { Console.WriteLine(e); } }
/** * Constructor * * @param w The workbook to interrogate * @param out The output stream to which the CSV values are written * @param encoding The encoding used by the output stream. Null or * unrecognized values cause the encoding to default to UTF8 * @exception java.io.IOException */ public Formulas(Workbook w, TextWriter os, string encoding) { if (encoding == null || encoding != "UnicodeBig") { encoding = "UTF8"; } try { //OutputStreamWriter osw = new OutputStreamWriter(out, encoding); //BufferedWriter os = new BufferedWriter(osw); ArrayList parseErrors = new ArrayList(); for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++) { Sheet s = w.getSheet(sheet); os.Write(s.getName()); os.WriteLine(); Cell[] row = null; Cell c = null; for (int i = 0; i < s.getRows(); i++) { row = s.getRow(i); for (int j = 0; j < row.Length; j++) { c = row[j]; if (c.getType() == CellType.NUMBER_FORMULA || c.getType() == CellType.STRING_FORMULA || c.getType() == CellType.BOOLEAN_FORMULA || c.getType() == CellType.DATE_FORMULA || c.getType() == CellType.FORMULA_ERROR) { FormulaCell nfc = (FormulaCell)c; StringBuilder sb = new StringBuilder(); CSharpJExcel.Jxl.Biff.CellReferenceHelper.getCellReference(c.getColumn(), c.getRow(), sb); try { os.Write("Formula in " + sb.ToString() + " value: " + c.getContents()); os.Flush(); os.Write(" formula: " + nfc.getFormula()); os.Flush(); os.WriteLine(); } catch (FormulaException e) { os.WriteLine(); parseErrors.Add(s.getName() + '!' + sb.ToString() + ": " + e); } } } } } os.Flush(); // os.close(); if (parseErrors.Count > 0) { Console.WriteLine(); Console.WriteLine("There were " + parseErrors.Count + " errors"); foreach (object s in parseErrors) Console.WriteLine(s.ToString()); } } catch (Exception e) { Console.WriteLine(e); } }