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();
}
}