码迷,mamicode.com
首页 > 编程语言 > 详细

【自动化__持续集成】___java___excel__jxl读

时间:2017-09-07 23:05:12      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:student   ++   otf   not   str   代码   work   static   data   

一、代码如下

package com.wujianbo.five;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.demo.Demo;
import jxl.read.biff.BiffException;

public class Demo05 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Demo05 demo05= new Demo05();
		demo05.readExcelByJxl();

	}
	
	public void readExcelByJxl() {
		String path= System.getProperty("user.dir");
		path= path + "\\data\\Students.xls";
		//System.out.println(path);
		try {
			File file= new File(path);
			FileInputStream fis= new FileInputStream(file);
			jxl.Workbook rwb= Workbook.getWorkbook(fis);
			
			Sheet[] sheet= rwb.getSheets();
			for(int i=0; i<sheet.length; i++) {
				Sheet rs= rwb.getSheet(i);
				for(int j=0; j<rs.getRows(); j++) {
					Cell[] cells= rs.getRow(j);
					for(int k=0;k<cells.length; k++) {
						System.out.print(cells[k].getContents());
						System.out.print("\t");
						
					}
					System.out.println();
					
				}
			}
			fis.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BiffException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IndexOutOfBoundsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

 

【自动化__持续集成】___java___excel__jxl读

标签:student   ++   otf   not   str   代码   work   static   data   

原文地址:http://www.cnblogs.com/wujianbo123/p/7492185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!