首页>代码>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();
        }
	}
	
}
最近下载更多
                
                haomc052829     LV4
                2024年12月9日
            
            
        
                467277     LV13
                2024年2月27日
            
            
        
                newhaijun     LV16
                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日
            
            
        
最近浏览更多
                
                dane168     LV10
                8月5日
            
            
        
                qiheideguang     LV18
                4月10日
            
            
        
                haomc052829     LV4
                2024年12月9日
            
            
        
                3334004690     LV11
                2024年6月24日
            
            
        
                sccs1984     LV15
                2024年5月4日
            
            
        
                467277     LV13
                2024年2月27日
            
            
        
                floweyws     LV6
                2024年2月5日
            
            
        
                zhangjilu     LV18
                2023年4月7日
            
            
        
                newhaijun     LV16
                2023年3月19日
            
            
        
                doutao6677     LV25
                2023年2月10日
            
            
        
    
    
    