formula的java用法_如何用Java得到Excel中Formula的值

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 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值