zoukankan      html  css  js  c++  java
  • excel表格加减法

    package it.excle.a;
    import java.io.*;
    import java.math.BigDecimal;

    import jxl.*;
    import jxl.read.biff.BiffException;

    public class excle{
    public static void main(String[] args) {
    File file = new File("d:\excle.xls");

    InputStream in = null;
    try {
    in = new FileInputStream(file);
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Workbook workbook = null;
    try {
    workbook = Workbook.getWorkbook(in);
    } catch (BiffException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    //获取第一张Sheet表
    Sheet sheet = workbook.getSheet(0);

    //我们既可能通过Sheet的名称来访问它,也可以通过下标来访问它。如果通过下标来访问的话,要注意的一点是下标从0开始,就像数组一样。
    //获取第一行,第一列的值
    // Cell c00 = sheet.getCell(1, 3);
    // String strc00 = c00.getContents();
    // System.out.println(strc00);


    Cell[] column_0 = sheet.getColumn(0);
    Cell[] column_2 = sheet.getColumn(2);
    Cell[] column_1 = sheet.getColumn(1);
    int l=column_0.length;

    for(int i=0;i<l;i++){
    // System.out.print(column_0[i].getContents()+" ");
    // System.out.print(column_1[i].getContents()+" ");
    // System.out.println(column_2[i].getContents());
    BigDecimal b1=new BigDecimal(column_0[i].getContents());
    BigDecimal b2=new BigDecimal(column_1[i].getContents());
    BigDecimal b3=new BigDecimal(column_2[i].getContents());
    if((b1.add(b2).doubleValue())!=b3.doubleValue()){
    System.out.println("有错的行为:"+(i+1));
    }
    // try {
    // float a = Float.parseFloat(column_0[i].getContents());
    // float b = Float.parseFloat(column_1[i].getContents());
    // float c = Float.parseFloat(column_2[i].getContents());
    // if((a+b)!=c){
    // System.out.println("有错的行为:"+(i+1));
    // }
    //
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    }

    }
    }

    jar包下载链接:http://pan.baidu.com/s/1bsdPNK

  • 相关阅读:
    EL表达式具体解释
    Android 实战美女拼图游戏 你能坚持到第几关
    redis sentinel安装及配置(单机版)
    ElasticSearch scroll查询 api
    springboot自动配置原理
    kafka实践
    Springboot mybatis
    计算机原理
    快速排序算法
    maven常见报错问题
  • 原文地址:https://www.cnblogs.com/miffy/p/5147831.html
Copyright © 2011-2022 走看看