一、导入 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();
}
}
}