hutool操作word模板赋值
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.7</version>
</dependency>
导出到指定文件目录(后面提供下载版)
public static void main(String[] args) {
/*
* 行间距没有到怎么设置的,用的换行????
* */
Word07Writer writer = new Word07Writer();
前端页面模板// 添加段落(标题)居中
writer.addText(ParagraphAlignment.CENTER,new Font("方正小标宋简体", Font.PLAIN, 15), "18旅游政策法规");
writer.addText(ParagraphAlignment.RIGHT,new Font("方正小标宋简体", Font.PLAIN, 10), "模拟");
// 添加段落(正文)
writer.addText(new Font("宋体", Font.PLAIN, 10), "一、单选题(共50题,每题1.00分)");
for (int i=0;i<50;i++){ //单选
writer.addText(new Font("宋体", Font.PLAIN, 10), i+1+".中国特社会主义法律体系已经形成是在( )上宣布的。");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "A:十一届全国人大三次会议");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "B:十一届全国人大四次会议");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "C:十二届全国人大三次会议");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "D:十二届全国人大四次会议");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
}
writer.addText(new Font("宋体", Font.PLAIN, 15), "二、多选题(共30题,每题1.00分)");
for (int i=0;i<30;i++){ //多选
writer.addText(new Font("宋体", Font.PLAIN, 12), i+1+".加强重点领域立法主要包括( )");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "A:完善宪法监督制度");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "B:推进社会主义民主政治法治化");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "C:建立健全文化法律制度");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "D:加强社会建设领域法制制度建设");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 10), "E:用严格的法律制度保护生态环境");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
}
writer.addText(new Font("宋体", Font.PLAIN, 15), "三、判断题(共20题,每题1.00分)");
for (int i=0;i<20;i++){ //判断
writer.addText(new Font("宋体", Font.PLAIN, 12), i+1+".《“十三五”旅游业发展规划》是由国家旅游局独立编制和发布的“十三五”时期旅游业发展的行动纲领和基本遵循。( )");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
writer.addText(new Font("宋体", Font.PLAIN, 8), "");
}
// 写出到文件
writer.flush(FileUtil.file("D:/wordWrite.docx"));
// 关闭
writer.close();
}
提供前端页面下载
public void exportExamTestPaper(HttpServletResponse response, @RequestParam(value = "testPaperId") Integer testPaperId) throws Exception {
//中间逻辑省略
// 导出到response输出流中
ServletOutputStream os = OutputStream();
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
String fileName = ClassificationName() + ".docx";
response.setHeader("Content-Disposition", "attachment;filename=".concat(String.de(fileName, "UTF-8"))));
writer.flush(os);
os.close();
writer.close();
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论