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

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; } }

 

转载于:https://www.cnblogs.com/dreamShines/p/11505565.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值