![struts2实现excel导出_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-1/16/4c1c99ed-a75b-48bb-a7a6-5fea13402144/4c1c99ed-a75b-48bb-a7a6-5fea134021441.gif)
![struts2实现excel导出_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-1/16/4c1c99ed-a75b-48bb-a7a6-5fea13402144/4c1c99ed-a75b-48bb-a7a6-5fea134021442.gif)
![struts2实现excel导出_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-1/16/4c1c99ed-a75b-48bb-a7a6-5fea13402144/4c1c99ed-a75b-48bb-a7a6-5fea134021443.gif)
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、用到的是poi的包。在apache的网站上去下poi-bin-3.2-FINAL-20081019.zip,目前最新的版本。直接上代码了:action:import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.ps.model.UserBizInfo;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.Inpu
2、tStream;import java.io.OutputStream;import java.util.List;import java.util.Map;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFRichTextString;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.
3、usermodel.HSSFWorkbook;public class ExcelDownloadAction extends ActionSupport public InputStream getInputStream() Map session=ActionContext.getContext().getSession(); List<UserBizInfo> list=(List<UserBizInfo>)session.get("ecxelUserBizInfolist"); HSSFWorkbook wb = new HSSFWorkbo
4、ok(); HSSFSheet sheet = wb.createSheet("sheet1"); int rowNum = 0; / 标题开始行 int colNum = 0; / 标题开始列 / HSSFRow excell的头 HSSFRow row = sheet.createRow(rowNum+); / HSSFCell excell的格子单元 HSSFCell cell = row.createCell(short)colNum+); cell.setCellValue("Id"); cell = row.createCell(short)
5、colNum+); cell.setCellValue("用户名"); cell = row.createCell(short)colNum+); cell.setCellValue("类型"); for(UserBizInfo user : list) row = sheet.createRow(rowNum+); colNum=0; cell = row.createCell(short) colNum+); /cell.setCellStyle(cellStyle); String userid=String.valueOf(user.getUse
6、rId(); cell.setCellValue(new HSSFRichTextString(userid); cell = row.createCell(short) colNum+); /cell.setCellStyle(cellStyle); cell.setCellValue(new HSSFRichTextString(user.getUserName(); cell = row.createCell(short) colNum+); /cell.setCellStyle(cellStyle); int type=user.getUserType(); String userty
7、pe="不限" if(type=1) usertype="一般用户" else if(type=2) usertype="摄影师" cell.setCellValue(new HSSFRichTextString(usertype); File file = new File("abc.xls"); /创建一个File 拿来当缓存用.也就是先将内存中的excel写入File中.然后再将File转换成输出流 try OutputStream out = new FileOutputStream(file); wb.w
8、rite(out);/写入File out.close(); catch (Exception e) e.printStackTrace(); InputStream in = null; try in = new FileInputStream(file);/将file转换成输入流 /in.close(); catch (Exception e) / TODO Auto-generated catch block e.printStackTrace(); return in; public String execute() throws Exception try return SUCCES
9、S; catch (Exception e1) e1.printStackTrace(); return ERROR; struts2配置<action name="excel" class="com.ps.action.adminaction.ExcelDownloadAction"> <result name="success" type="stream"> <param name="contentType">application/vnd.ms-excel</param> <param name="contentDisposition">attachment;filename="AllUsers.xls"</param> <p
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 文明校园创建活动方案
- 五年级上册英语教案-Lesson 12 Maddy's Family Photos |冀教版(三起)
- 国内低空经济发展现状
- 专项资金管理制度
- 城市更新与经济发展的内在联系
- 贵阳市2024届高三年级摸底考试语文试题及参考答案
- 一年级下册美术教学设计-第十四课《介绍我喜欢的玩具》 人美版
- 实验四-LED跑马灯
- 上海市浦东新区2024届高三年级下册三模试题 语文 含解析
- DB32T 4737.2-2024 社区慢性病患者自我管理工作规范 第2部分:高血压
- 2024年上海青浦区赵巷镇工作人员招聘笔试参考题库附带答案详解
- 2024年天津市渤海轻工投资集团有限公司招聘笔试参考题库含答案解析
- 2024年日历表(空白)(一月一张-可编辑做工作日历)
- 2022-2023学年四川省德阳市旌阳区八年级(下)期末英语试卷(含解析)
- 网银U盾管理细则
- 超全的F分布表f分布表完整表
- 河北省用水定额
- 六年级学生英语学情分析参考
- 律师见证书(中英)LAWYERATTESTATIONLETTER
- 拱顶罐施工方案
评论
0/150
提交评论