jxl读取excel

mportjava.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;

/**
*
@authorHayVanpull
*
*/
publicclassJXLTOOL
{
privateWorkbookworkbook=null;//工作部对象

privateHashMap<String,String>mapData=null;//data数据

privateSheetsheet=null;//工作表

publicinttotalRows=0;//总行数

publicinttotalCells=0;//总列数

/**
*以一个InputStream为参数的构造器
*
*
@paraminputStream
*
@throwsIOException
*
@throwsBiffException
*/
publicJXLTOOL(InputStreaminputStream)throwsBiffException,IOException
{
this.workbook=Workbook.getWorkbook(inputStream);
this.sheet=this.workbook.getSheet(0);
this.getRows();
this.getCells();
}

/**
*以一个StrutsFormFile为参数的构造器
*
*
@paramfile
*
@throwsIOException
*
@throwsFileNotFoundException
*
@throwsBiffException
*/
publicJXLTOOL(FormFilefile)throwsFileNotFoundException,IOException,
BiffException
{
this(file.getInputStream());
}

/**
*以一个File为参数的构造器
*
*
@paramfile
*
@throwsIOException
*
@throwsBiffException
*/
publicJXLTOOL(Filefile)throwsBiffException,IOException
{
this(newFileInputStream(file));
}

/**
*以一个文件路径path的构造器
*
*
@paramfilePath
*
@throwsIOException
*
@throwsBiffException
*/
publicJXLTOOL(StringfilePath)throwsBiffException,IOException
{

this(newFile(filePath));
}

/**
*把所有数据放到一个map中去,key为行号加列号
*
*
@return
*/
publicHashMap<String,String>getExcelDate()
{
mapData
=newHashMap<String,String>();
for(inti=0;i<this.totalRows;i++)
{
for(intj=0;j<this.totalCells;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
*/
privateStringgetData(intcell,introw)
{
Cellrs
=this.sheet.getCell(cell,row);
returnrs.getContents();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值