http://blog.csdn.net/tkd03072010/article/details/6692366
操作步骤:
1.首先到网上载一下JExcelApi rar包,目前最新是:jexcelapi_2_6_12.tar,然后将其解压开,将 jxl.jar文件Copy到WEB-INF\lib目录下或直接导入到Java项目中2.相应的操作代码如下:
- package com.xqh.java.test;
- import java.io.File;
- import java.io.IOException;
- import jxl.Cell;
- import jxl.Sheet;
- import jxl.Workbook;
- import jxl.read.biff.BiffException;
- public class JavaReadExcel {
- public static void main(String[] args) {
- try {
- String fileName = "?:\\...\\XXX.xlsx"; // 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表中的内容
- for (int j = 0; j < sheet.getColumns(); j++) {
- Cell cell = sheet.getCell(j, i);
- System.out.println(cell.getContents());
- }
- System.out.println();
- }
- } catch (BiffException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }