使用vo注释做一个poi导出功能
生活随笔
收集整理的這篇文章主要介紹了
使用vo注释做一个poi导出功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 jsp中:
<a href="${basePath}/manage/bulletinAction.do?method=exportMainProduct&is18th=1">導出公司主營產品</a>2 action中:
/*** 導出主營產品*/public void exportMainProduct(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {BulletinForm bulletinForm = (BulletinForm) form;bulletinForm.setRows(5000);List<Bulletin> list = bulletinService.find(bulletinForm);List<MainproductcnVo> mainproductcnVos = new ArrayList<MainproductcnVo>();Iterator<Bulletin> it = list.iterator();while (it.hasNext()) {Bulletin bulletin = (Bulletin) it.next();MainproductcnVo mainproductcnVo = new MainproductcnVo();BeanUtils.copyProperties(bulletin, mainproductcnVo);mainproductcnVos.add(mainproductcnVo);}SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("CIOE2017主營產品", "導出時間:" + format.format(new Date()),"CIOE2017主營產品"), MainproductcnVo.class, mainproductcnVos);//主要!!用這一句話確定導出內容OutputStream ops = null;try {ops = response.getOutputStream();response.reset();response.setContentType("application/octet-stream");response.setHeader("Content-Disposition","attachment; filename=mainproduct.xls");// ops=new FileOutputStream("D:/AudienceRecord.xls");workbook.write(ops);ops.flush();System.out.println("ok");} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO: handle exceptione.printStackTrace();} finally {if (ops != null) {try {ops.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}3 vo中,注釋:
public class MainproductcnVo {@Excel(name = "公司中文名稱", orderNum = "1")private String companynameCn;@Excel(name = "公司英文名稱", orderNum = "2")private String companynameEn;@Excel(name="主營產品",orderNum = "3")private String mainproductcn;@Excel(name="電話",orderNum = "4")private String tel;@Excel(name="郵箱",orderNum = "5")private String email;//省略set/get方法 }總結
以上是生活随笔為你收集整理的使用vo注释做一个poi导出功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓短信恢复(安卓手机恢复短信)
- 下一篇: log4j入门实例