java 读取 jxl_JXL 读取 Excel

importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.IOException;importjava.io.InputStream;importjava.util.HashMap;importjxl.Cell;importjxl.Sheet;importjxl.Workbook;importjxl.read.biff.BiffException;importorg.apache.struts.upload.FormFile;/***@authorHay Vanpull

**/publicclassJXLTOOL

{privateWorkbook                workbook=null;//工作部对象privateHashMapmapData=null;//data数据privateSheet                   sheet=null;//工作表publicinttotalRows=0;//总行数publicinttotalCells=0;//总列数/*** 以一个InputStream为参数的构造器

*

*@paraminputStream

*@throwsIOException

*@throwsBiffException*/publicJXLTOOL(InputStream inputStream)throwsBiffException, IOException

{this.workbook=Workbook.getWorkbook(inputStream);this.sheet=this.workbook.getSheet(0);this.getRows();this.getCells();

}/*** 以一个Struts FormFile为参数的构造器

*

*@paramfile

*@throwsIOException

*@throwsFileNotFoundException

*@throwsBiffException*/publicJXLTOOL(FormFile file)throwsFileNotFoundException, IOException,

BiffException

{this(file.getInputStream());

}/*** 以一个File为参数的构造器

*

*@paramfile

*@throwsIOException

*@throwsBiffException*/publicJXLTOOL(File file)throwsBiffException, IOException

{this(newFileInputStream(file));

}/*** 以一个文件路径path的构造器

*

*@paramfilePath

*@throwsIOException

*@throwsBiffException*/publicJXLTOOL(String filePath)throwsBiffException, IOException

{this(newFile(filePath));

}/*** 把所有数据放到一个map中去,key为行号加列号

*

*@return*/publicHashMapgetExcelDate()

{

mapData=newHashMap();for(inti=0; i

{for(intj=0; j

{this.mapData.put(i+""+j,this.getData(j, i));

}

}returnthis.mapData;

}/*** 得到总行数*/privatevoidgetRows()

{this.totalRows=sheet.getRows();

}/*** 得到总列数*/privatevoidgetCells()

{this.totalCells=this.sheet.getColumns();

}/*** 得到数据

*

*@paramcell

*@paramrow

*@return*/privateString getData(intcell,introw)

{

Cell rs=this.sheet.getCell(cell, row);returnrs.getContents();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值