1 importjava.io.BufferedWriter;2 importjava.io.File;3 importjava.io.IOException;4 importjava.io.OutputStream;5 importjava.io.OutputStreamWriter;6 importjava.io.UnsupportedEncodingException;7 8 importjava.util.ArrayList;9 importjava.util.Iterator;10 11 importjxl.Cell;12 importjxl.CellType;13 importjxl.FormulaCell;14 importjxl.Sheet;15 importjxl.Workbook;16 importjxl.biff.CellReferenceHelper;17 importjxl.biff.formula.FormulaException;18 19 /**20 * Goes through each cell in the workbook, and if the contents of that cell is a21 * formula, it prints out the last calculated value and the formula string22 */23 publicclassFormulas {24 25 publicstaticvoidmain(String[] args) {26 String file="jxlrwtest.xls";27 String encoding="UTF8";28 try{29 Workbook w=Workbook.getWorkbook(newFile(file));30 Formulas f=newFormulas(w, System.out, encoding);31 w.close();32 }catch(Exception e) {33 e.printStackTrace();34 }35 }36 37 /**38 * Constructor39 *40 *@paramw41 * The workbook to interrogate42 *@paramout43 * The output stream to which the CSV values are written44 *@paramencoding45 * The encoding used by the output stream. Null or unrecognized46 * values cause the encoding to default to UTF847 *@exceptionjava.io.IOException48 */49 publicFormulas(Workbook w, OutputStream out, String encoding)50 throwsIOException {51 if(encoding==null||!encoding.equals("UnicodeBig")) {52 encoding="UTF8";53 }54 55 try{56 OutputStreamWriter osw=newOutputStreamWriter(out, encoding);57 BufferedWriter bw=newBufferedWriter(osw);58 59 ArrayList parseErrors=newArrayList();60 61 for(intsheet=0; sheet0) {106 System.err.println();107 System.err.println("There were"+parseErrors.size()108 +"errors");109 110 Iterator i=parseErrors.iterator();111 while(i.hasNext()) {112 System.err.println(i.next());113 }114 }115 }catch(UnsupportedEncodingException e) {116 System.err.println(e.toString());117 }118 }119 }
formula的java用法_如何用Java得到Excel中Formula的值
最新推荐文章于 2024-08-12 02:08:18 发布