码迷,mamicode.com
首页 > 其他好文 > 详细

poi读取模板,填充模板数据,导出修改后的模板

时间:2019-09-11 13:30:20      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:todo   encoding   real   book   his   set   apach   export   position   

public void to_exportAllAssess(){
ArrayList
<AssessResultDetail> assessResultDetailList = 查询准备填充excel的数据 HSSFWorkbook workbook = AssessExportUtil.exportAllAssess(assessResultDetailList); try { //响应到客户端 this.setResponseHeader(response, assessTime.getName()+"统计表.xls"); OutputStream os = response.getOutputStream(); workbook.write(os); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } } //发送响应流方法 public void setResponseHeader(HttpServletResponse response, String fileName) { try { try { fileName = new String(fileName.getBytes(),"ISO8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } response.setContentType("application/octet-stream;charset=ISO8859-1"); response.setHeader("Content-Disposition", "attachment;filename="+ fileName); response.addHeader("Pargam", "no-cache"); response.addHeader("Cache-Control", "no-cache"); } catch (Exception ex) { ex.printStackTrace(); } }
package com.*.util;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts2.ServletActionContext;
import com.*.AssessResultDetail;

public class AssessExportUtil {
    /*
    HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
    XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx*/
    public static HSSFWorkbook exportAllAssess(ArrayList<AssessResultDetail> assessResultDetailList) {
        //excel模板路径
        File file = new File(ServletActionContext.getServletContext().getRealPath("/WEB-INF/templet/"), "assessValue.xls");
        HSSFWorkbook workbook = null;
         if(file.exists()) {    //文件存在
             try {//创建workbook
                 workbook = new HSSFWorkbook(new FileInputStream(file));
          //TODO 数据填充excel }
catch(Exception e){ e.printStackTrace(); } } return workbook; } }

 

poi读取模板,填充模板数据,导出修改后的模板

标签:todo   encoding   real   book   his   set   apach   export   position   

原文地址:https://www.cnblogs.com/dreamShines/p/11505565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!