使用java读取execel

需要下载jxl.jar,去官网下载

代码如下:

//import java.io.*;
//import java.util.Scanner;
//
///**
// * @author Administrator
// * @version 1.0
// * @Date 2011-06-07 java练习
// */
//public class Test7 {
//
// /**
//  * 主函数
//  *
//  * @param args
//  */
// public static void main(String[] args) throws Exception {
//
//  Test7 test7 = new Test7();
//  test7.print();
//  test7.print1();
// }
//
// /**
//  * 计算并输出1-1000中所有偶数的和
//  *
//  * @throws IOException
//  */
// public void print() throws IOException {
//  int cn = 0;
//  for (int i = 1; i < 1000; i++) {
//   if (i % 2 == 0) {
//    cn += i;
//   }
//  }
//  System.out.println(cn);
// }
//
// /**
//  * 输出杨辉三角
//  */
// public void print1() {
//  Scanner sc = new Scanner(System.in);
//  System.out.println("请输入行数:");
//  int n = sc.nextInt();
//  int a[][] = new int[n][n];
//  int i, j;
//  for (i = 0; i < n; i++) {
//   a[i][i] = new Integer(1);
//   a[i][0] = new Integer(1);
//  }
//  for (i = 2; i < n; i++) {
//   for (j = 1; j <= i - 1; j++)
//    a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
//  }
//  for (i = 0; i < n; i++) {
//   for (j = 0; j <= i; j++)
//    System.out.printf("%6d", a[i][j]);
//   System.out.println();
//  }
// }
//}

 

import java.io.File; 
import java.io.IOException; 
 
import jxl.Cell; 
import jxl.Sheet; 
import jxl.Workbook; 
import jxl.read.biff.BiffException; 
 
public class Test7 { 
 
    /**
     * @param args
     */ 
    public static void main(String[] args) { 
        try { 
            //得到工作薄  
            Workbook workbook = Workbook.getWorkbook(new File("D:/日常开销.xls")); 
            //得到工作区  
            Sheet sheet = workbook.getSheet(0); 
            //得到单元格  
            Cell cell00 = sheet.getCell(0,0); 
            Cell cell01 = sheet.getCell(0,1); 
            Cell cell02 = sheet.getCell(0,2); 
            Cell cell03 = sheet.getCell(1,0); 
            System.out.println("第1个" + cell00.getContents());
            System.out.println("第2个" + cell01.getContents());
            System.out.println("第3个" + cell02.getContents());
            System.out.println("第4个" + cell03.getContents());
           
            //得到列数  
            int columCount = sheet.getColumns(); 
            //得到行数  
            int rowCount = sheet.getRows(); 
             
            System.out.println("行数"+columCount); 
            System.out.println("列数"+rowCount); 
             
            for(int i=0;i<rowCount;i++){ 
                System.out.print("第"+(i+1)+"行的内容是:"); 
                for(int j=0;j<columCount;j++){ 
                    Cell cell = sheet.getCell(j,i);              
                    System.out.print(cell.getContents()+"\t"); 
                } 
                System.out.println(""); 
            }    
             
        } catch (BiffException e) { 
            // TODO Auto-generated catch block  
            e.printStackTrace(); 
        } catch (IOException e) { 
            // TODO Auto-generated catch block  
            e.printStackTrace(); 
        } 
 
    } 
 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值