欢迎来到天天文库
浏览记录
ID:34723957
大小:130.18 KB
页数:13页
时间:2019-03-10
《jsp中poi实现导入导出excel》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.excel导入数据导入时候注意数字类型和字符类型的区别,数字类型要在excel中设置数字类型,对应数据库中也应该建立对应类型<%@pageimport="com.guanri.database.*,java.util.*,com.guanri.util.*,com.jspsmart.upload.*"contentType="text/html;charset=GBK"%><%@pageimport="java.util.*,java.io.*,org.apache.poi.poifs.fil
2、esystem.*,org.apache.poi.hssf.usermodel.*"%><% Stringresult="";StringcontracId="";Stringprojectname="";doubleprojectscale=0;Stringprojecttype="";Stringprojectconunit="";doubledesigntime=0;Stringdesignphase="";
3、doublecompletedtime=0;Stringparticipants="";Stringpositionofpro="";Stringdutiesas="";intinum=0;intunum=0;intrnum=0;intsnum=0;Stringrmstr="";Tabletb=newTable();Vectorvc=null;Hashtablerows=newHashtable();Stringsql="";if(request.getMethod().equalsIgnoreC
4、ase("POST")){ Stringsdir="/download/xlsdir/"; //文件保存目录 String filesep=System.getProperty("file.separator"); Stringssdir=filesep+"download"+filesep+"xlsdir"+filesep; Calendarc=Calendar.getInstance(); Stringfname=c.getTimeInMillis()+".xls"; Stringsfn
5、ame=sdir+fname; Stringss="xls"; //支持的文件后缀名 try{ SmartUploadsu=newSmartUpload(); su.initialize(pageContext); su.setAllowedFilesList(ss); su.upload(); com.jspsmart.upload.Filefile=su.getFiles().getFile(0); if(!file.isMissing()){ file.saveAs(sf
6、name); // System.out.println(application.getRealPath("/")+ssdir+fname); FileInputStreamfinput=newFileInputStream(application.getRealPath("/")+ssdir+fname); //设定FileINputStream读取Excel档 POIFSFileSystemfs=newPOIFSFileSystem(finput); HSSFWorkboo
7、kwb=newHSSFWorkbook(fs); HSSFSheetsheet=wb.getSheetAt(0); //读取第一个工作表,宣告其为sheet finput.close(); HSSFRowrow=null; //宣告一列 HSSFCellcell=null; //宣告一个储存格 shorti=0; shorty=0; //以巢状迴圈读取所有储存格资料 System.out.println("sheet.getLastRowNum
8、()="+sheet.getLastRowNum()); for(i=1;i<=sheet.getLastRowNum();i++) { row=sheet.getRow(i); for(y=1;y<=row.getLastCellNum();y++) { cell=row.getCell(y); switch(y){ case1: //合同号 if(cell!=null){
此文档下载收益归作者所有