jxl读取excel文件
来源:互联网 发布:淘宝假货可以不退货吗 编辑:程序博客网 时间:2024/05/16 09:19
package com.excel;import java.io.File;import jxl.Cell;import jxl.Sheet;import jxl.Workbook;/** * jxl对excel读取工具类 * @author huweijun * @date 2015-01-29 22:22:22 * */public abstract class JxlExcelHandler {/** * 文件路径 */private File file;/** * 第几个工作表(从0开始,默认为0) */private int sheetIndex = 0;/** * 第几行(从0开始,默认为0) */private int rowIndex = 0;public JxlExcelHandler(String path){this.file = new File(path);}/** * @param pathxls文件路径 * @param rowIndex从第几行开始(默认0) * @author huweijun * @date 2015-01-29 22:22:22 */public JxlExcelHandler(String path,int rowIndex){this.file = new File(path);this.rowIndex = rowIndex;}/** * @param pathxls文件路径 * @param rowIndex从第几行开始(默认0) * @param sheetIndex从第几个工作表开始(默认0) * @author huweijun * @date 2015-01-29 22:22:22 */public JxlExcelHandler(String path,int rowIndex,int sheetIndex){this.file = new File(path);this.rowIndex = rowIndex;this.sheetIndex = sheetIndex;}/** * 执行 * @author huweijun * @date 2015-01-29 22:22:22 */public void print(){Workbook book = null;try {book = Workbook.getWorkbook(file);Sheet sheet = book.getSheet(sheetIndex);int totalRow = sheet.getRows();for (int i=rowIndex; i<totalRow-1; i++) {handlerRow(sheet.getRow(i),i,totalRow-1);}} catch (Exception e) {e.printStackTrace();} finally{if(book != null){book.close();}}}/** * 从0遍历cell * @param row 一行的所有cell * @param index 第几行(从0开始) * @param totalRow 总共多少行 * @author huweijun * @date 2015-01-29 22:22:22 */public abstract void handlerRow(Cell[] row,int index,int totalRow);}
package com.excel;import jxl.Cell;/** * 测试jxl对excel读取 * @author huweijun * @date 2015-01-29 22:22:22 * */public class JxlExcelTest{public static void main(String[] args) {String file = "C:\\Users\\Administrator\\Desktop\\test.xls";final int startRow = 1;new JxlExcelHandler(file,startRow) {@Overridepublic void handlerRow(Cell[] row, int index,int totalRow) {String msg = row[0].getContents()+" "+row[1].getContents()+" "+row[2].getContents()+" 第 "+(index+1)+" 行 总共:" +totalRow+" 行; 总共读取了:"+(totalRow-startRow)+"行.";System.out.println(msg);}}.print();}}
jar包下载==>>>
0 0
- jxl读取excel文件
- jxl读取excel文件
- jxl读取excel文件
- jxl 读取 Excel文件
- excel文件读取例子-jxl
- jxl读取excel文件操作
- java jxl 读取excel文件
- 实践jxl读取excel文件
- 用jxl读取Excel文件
- poi,jxl读取excel文件
- jxl读取excel文件中的时间类型
- 用jxl.jar读取Excel文件内容
- java读取excel文件(使用jxl)
- JXL读取Excel文件测试代码
- Java:使用jxl读取excel文件内容
- 利用jxl.jar读取EXCEL文件
- [JAVA] java读取Excel文件内容,jxl(Excel 2003)
- jxl 读取Excel图片
- vim配置文件
- 【SzNOI语法百题】【d036】四渠注水from九章算术
- 时间换算
- 商品信息管理系统
- UIXO协议
- jxl读取excel文件
- 异或运算的性质
- 汇编语言:基于Linux环境
- 信号报告
- poj 1691 dfs(矩形涂色)
- 自己动手(一)──可拖动排序的 ListView(1)
- android中的ellipsize(textview中内容过长加省略号)
- Json
- 【SzNOI语法百题】【d037】鸡兔同笼