public class WordTest {
private Configuration configuration = null;
public WordTest(){
configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
}
public static void main(String[] args) {
WordTest test = new WordTest();
test.createWord();
}
public void createWord(){
Map<String,Object> dataMap=new HashMap<String,Object>();
getData(dataMap);
configuration.setClassForTemplateLoading(this.getClass(), "");//模板文件所在路径
Template t=null;
try {
t = configuration.getTemplate("测试.ftl"); //获取模板文件
} catch (IOException e) {
e.printStackTrace();
}
File outFile = new File("D:/outFile"+Math.random()*10000+".doc"); //导出文件
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
t.process(dataMap, out); //将填充数据填入模板文件并输出到目标文件
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void getData(Map<String, Object> dataMap) {
dataMap.put("title", "标题");
dataMap.put("nian", "2016");
dataMap.put("yue", "3");
dataMap.put("ri", "6");
dataMap.put("shenheren", "lc");
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
for (int i = 0; i < 10; i++) {
Map<String,Object> map = new HashMap<String,Object>();
map.put("xuehao", i);
map.put("neirong", "内容"+i);
list.add(map);
}
dataMap.put("list", list);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有