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