首页>代码>SpringBoot2.0根据word模板导出word文件>/src/main/java/cn/codepeople/controller/WordExportController.java
package cn.codepeople.controller;

import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import cn.afterturn.easypoi.word.WordExportUtil;

@Controller
public class WordExportController {

	
	@GetMapping("/index")
	public String index() {
		return "index.html";
	}
	
	@GetMapping("/exportword/{id}")
	public void exportwod(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) {
		
		Map<String,Object> map = new HashMap<>();
    	map.put("projectName", "项目的名称1234");
    	map.put("buildUnit", "项目的建设单位4321");
    	map.put("constructionUnit", "中铁十七建");
    	map.put("supervisionUnit", "中国监理公司");
    	map.put("projectProgress", "施工中");
    	map.put("projectAddress", "项目地址信息为长安街");
    	map.put("projectWorkerNum", "22人");
    	map.put("addWorkerNum", "12人");
    	map.put("projectProgressRemark", "项目进度备注");
    	map.put("provincialNum", "10人");
    	map.put("otherProvincialNum", "19人");
    	map.put("hubeiNum", "9人");
    	map.put("addProvincialNum", "12");
    	map.put("addOtherProvincialNum","11人");
    	map.put("addHubeiNum", "7人");
    	map.put("remark", "疫情期间注意勤洗手,戴口罩,不聚集");
    	String path = Thread.currentThread().getContextClassLoader().getResource("").getPath()+"static";
    	String   filename = "申请表";
    	try {
    		filename = new String(filename.getBytes("UTF-8"),"iso8859-1");
            XWPFDocument doc = WordExportUtil.exportWord07(
            		path+"/apply_word.docx", map);
            OutputStream os = response.getOutputStream();
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition","attachment;filename="+filename+".docx");//filename为导出的word的名字
            doc.write(os);
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
}
最近下载更多
467277  LV13 2月27日
newhaijun  LV15 2023年3月19日
Myangyyyy  LV10 2022年9月22日
xiaobaitud  LV13 2022年9月19日
crosa_Don  LV18 2022年6月2日
diyanzhao1  LV11 2022年3月14日
itcontect  LV9 2022年2月11日
PalyBoy  LV9 2021年11月27日
gshnlj  LV15 2021年11月24日
745075779  LV5 2021年11月12日
最近浏览更多
467277  LV13 2月27日
floweyws  LV6 2月5日
zhangjilu  LV18 2023年4月7日
newhaijun  LV15 2023年3月19日
doutao6677  LV25 2023年2月10日
interface  LV22 2023年2月7日
anhao5188 2022年12月12日
暂无贡献等级
1358849392  LV21 2022年11月11日
Myangyyyy  LV10 2022年9月22日
xiaobaitud  LV13 2022年9月19日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友