/** * 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 EscherDrawingGroup(Workbook w, TextWriter os, string encoding) { if (encoding == null || encoding != "UnicodeBig") { encoding = "UTF8"; } try { WorkbookParser wp = (WorkbookParser)w; DrawingGroup dg = wp.getDrawingGroup(); if (dg != null) { EscherDisplay ed = new EscherDisplay(dg, os); ed.display(); } os.WriteLine(); os.WriteLine(); 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 * @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 os The output stream to which the XML values are written * @param enc The encoding used by the output stream. Null or * unrecognized values cause the encoding to default to UTF8 * @param f Indicates whether the generated XML document should contain * the cell format information * @exception java.io.IOException */ public XML(Workbook w, TextWriter os, string enc, bool f) { encoding = enc; workbook = w; if (encoding == null || encoding != "UnicodeBig") { encoding = "UTF8"; } if (f) writeFormattedXML(os); else writeXML(os); }
/** * Creates a writable workbook as a copy of * the workbook passed input. Once created, the contents of the writable * workbook may be modified * * @param os the stream to write to * @param input the workbook to copy * @return a writable workbook * @exception IOException */ //public static WritableWorkbook createWorkbook(Stream os,Workbook input) // { // return createWorkbook(os,input,((WorkbookParser)input).getSettings()); // } /** * Creates a writable workbook as a copy of * the workbook passed input. Once created, the contents of the writable * workbook may be modified * * @param os the output stream to write to * @param input the workbook to copy * @param ws the configuration for this workbook * @return a writable workbook * @exception IOException */ public static WritableWorkbook createWorkbook(Stream os, Workbook input, WorkbookSettings ws) { WritableWorkbook w = new WritableWorkbookImpl(os, input, false, ws); return w; }
/** * Creates a writable workbook with the given filename as a copy of * the workbook passed input. Once created, the contents of the writable * workbook may be modified * * @param file the output file for the copy * @param input the workbook to copy * @param ws the configuration for this workbook * @return a writable workbook */ public static WritableWorkbook createWorkbook(FileInfo file, Workbook input, WorkbookSettings ws) { Stream fos = new FileStream(file.FullName,FileMode.Create); WritableWorkbook w = new WritableWorkbookImpl(fos,input,true,ws); return w; }
/** * Creates a writable workbook with the given filename as a copy of * the workbook passed input. Once created, the contents of the writable * workbook may be modified * * @param file the output file for the copy * @param input the workbook to copy * @return a writable workbook * @exception IOException */ public static WritableWorkbook createWorkbook(FileInfo file, Workbook input) { return createWorkbook(file,input,new WorkbookSettings()); }
/** * 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); } }
/** * Gets the fully qualified cell reference given the column, row * external sheet reference etc * * @param sheet the sheet * @param column the column * @param row the row * @param workbook the workbook * @return the cell reference in the form 'Sheet 1'!A1 */ public static string getCellReference(int sheet, int column, int row, Workbook workbook) { return CSharpJExcel.Jxl.Biff.CellReferenceHelper.getCellReference (sheet,column,row,(CSharpJExcel.Jxl.Biff.Formula.ExternalSheet)workbook); }
/** * Gets the fully qualified cell reference given the column, row * external sheet reference etc * * @param sheet the sheet * @param column the column * @param colabs TRUE if the column is an absolute reference * @param row the row * @param rowabs TRUE if the row is an absolute reference * @param workbook the workbook * @param buf the string buffer */ public static void getCellReference(int sheet, int column, bool colabs, int row, bool rowabs, Workbook workbook, StringBuilder buf) { CSharpJExcel.Jxl.Biff.CellReferenceHelper.getCellReference (sheet,column,colabs,row,rowabs, (CSharpJExcel.Jxl.Biff.Formula.ExternalSheet)workbook,buf); }
/** * A private method to test the various find functions */ private static void findTest(Workbook w) { Cell c = w.findCellByName("named1"); if (c != null) { Console.WriteLine("named1 contents: " + c.getContents()); } c = w.findCellByName("named2"); if (c != null) { Console.WriteLine("named2 contents: " + c.getContents()); } c = w.findCellByName("namedrange"); if (c != null) { Console.WriteLine("named2 contents: " + c.getContents()); } Range[] range = w.findByName("namedrange"); if (range != null) { c = range[0].getTopLeft(); Console.WriteLine("namedrange top left contents: " + c.getContents()); c = range[0].getBottomRight(); Console.WriteLine("namedrange bottom right contents: " + c.getContents()); } range = w.findByName("nonadjacentrange"); if (range != null) { for (int i = 0; i < range.Length; i++) { c = range[i].getTopLeft(); Console.WriteLine("nonadjacent top left contents: " + c.getContents()); c = range[i].getBottomRight(); Console.WriteLine("nonadjacent bottom right contents: " + c.getContents()); } } range = w.findByName("horizontalnonadjacentrange"); if (range != null) { for (int i = 0; i < range.Length; i++) { c = range[i].getTopLeft(); Console.WriteLine("horizontalnonadjacent top left contents: " + c.getContents()); c = range[i].getBottomRight(); Console.WriteLine("horizontalnonadjacent bottom right contents: " + c.getContents()); } } }