您的位置:首页 > 编程语言 > Java开发

java 使用jxl API 获取 Excel表格中的内容

2016-03-24 17:41 363 查看
一、导入 jxl-2.6.12.jar

二、直接看代码

package com.excel.mysj;

import java.io.File;

import java.io.IOException;

import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

import jxl.read.biff.BiffException;

public class TestExcelJXL {

public static void main(String args[]) {

try {

String fileName = "f:\\data.xls"; // Excel文件所在路径

File file = new File(fileName); // 创建文件对象

Workbook wb = Workbook.getWorkbook(file); // 从文件流中获取Excel工作区对象(WorkBook)

Sheet sheet = wb.getSheet(0); // 从工作区中取得页(Sheet)

for (int i = 0; i < sheet.getRows(); i++) { // 循环打印Excel表中的内容

Cell cell = sheet.getCell(0, i);

Cell cell2 = sheet.getCell(1, i);

String name = cell.getContents();

String idcard = cell2.getContents();

System.out.println(name);

System.out.println(idcard);

}

} catch (BiffException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java excel jxl