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();
}
}
}
二、直接看代码
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对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 使用Python生成Excel格式的图片
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序