欢迎来到天天文库
浏览记录
ID:55631424
大小:162.00 KB
页数:27页
时间:2020-05-21
《Excel数据在(jsp+ssh)环境下导入导出.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、导入导出EXCEL数据(jsp+ssh)1.首先搭建ssh框架(这儿不做介绍);2.导入jar包(如下):3.导出:(下面以一个例子的形式)1.新创建一个jsp页面如(export.jsp),在页面上添加如下代码:/indexAction!export.action">导出数据到excel2.进入indexAction.java文件,编写export方法由于要用到一个STUDENT类,就先编写STUDENT类,Student类代码如下:publicclassStudent{privateS
2、tringstudentId;privateStringstudentName;privateStringstudentSex;privateStringstudentDormitory;privateStringstudentSept;publicStringgetStudentId(){returnstudentId;}publicvoidsetStudentId(StringstudentId){this.studentId=studentId;}publicStringgetStudentName(){returnstud
3、entName;}publicvoidsetStudentName(StringstudentName){this.studentName=studentName;}publicStringgetStudentSex(){returnstudentSex;}publicvoidsetStudentSex(StringstudentSex){this.studentSex=studentSex;}publicStringgetStudentDormitory(){returnstudentDormitory;}publicvoids
4、etStudentDormitory(StringstudentDormitory){this.studentDormitory=studentDormitory;}publicStringgetStudentSept(){returnstudentSept;}publicvoidsetStudentSept(StringstudentSept){this.studentSept=studentSept;}}编写export方法:代码如下/***导出数据到excel*@return*@throwsException*/public
5、Stringexport()throwsException{/***如果是从数据库里面取数据,就让studentList=取数据的函数:*就没必要下面的for循环*我下面的for循环就是手动给studentList赋值*/ListstudentList=newArrayList();//学生LIstfor(inti=0;i<10;i++){Studentstudent=newStudent();//学生对象student.setStudentId(""+i);student.setStudentName("杨波"
6、+i);student.setStudentSex("男");student.setStudentDormitory("14-20"+i);student.setStudentSept("软件工程系");studentList.add(student);}/*设置表头:对Excel每列取名*(必须根据你取的数据编写)*/String[]tableHeader={"学号","姓名","性别","寝室号","所在系"};/**下面的都可以拷贝不用编写*/shortcellNumber=(short)tableHeader.length
7、;//表的列数HSSFWorkbookworkbook=newHSSFWorkbook();//创建一个excelHSSFCellcell=null;//Excel的列HSSFRowrow=null;//Excel的行HSSFCellStylestyle=workbook.createCellStyle();//设置表头的类型style.setAlignment(HSSFCellStyle.ALIGN_CENTER);HSSFCellStylestyle1=workbook.createCellStyle();//设置数据类型st
8、yle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);HSSFFontfont=workbook.createFont();//设置字体HSSFSheetsheet=workbook.createSheet("
此文档下载收益归作者所有