java导出 world
来源:互联网 发布:node.js版本 编辑:程序博客网 时间:2024/06/13 10:04
上图:是Word文档中的内容,也就是模板,为了下面步鄹做铺垫,所以在需要输入数据的地方改成了拼音,
将word文档另存为xml文件.
接下来,上面写的拼音就起到作用了.
打开xml文件.搜索 title.
将Title 改为 ${title}
其他地方一样的修改。
改完后,把文件的后缀名直接改成ftl。
java代码:
1:
try {
//创建配置实例
Configuration configuration = new Configuration();
//设置编码
configuration.setDefaultEncoding("UTF-8");
//ftl模板文件统一放至 com.lun.template 包下面
configuration.setClassForTemplateLoading(World.class,"/com/test/world/");
String templateName="test.ftl";
//获取模板
Template template = configuration.getTemplate(templateName);
String filePath="D:/";
String fileName="test.doc";
//输出文件
File outFile = new File(filePath+File.separator+fileName);
//如果输出目标文件夹不存在,则创建
if (!outFile.getParentFile().exists()){
outFile.getParentFile().mkdirs();
}
//将模板和数据模型合并生成文件
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8"));
//导入数据
Test1 tt=new Test1();
int id=2;
People pp= tt.getPeople(id);
Map<String,Object> dataMap=new HashMap<String,Object>();
//** 放置数据 **//*
tt.makeExportProWorkOrderData(pp,dataMap);
//生成文件
template.process(dataMap, out);
//关闭流
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
2:
public void makeExportProWorkOrderData(People p,Map<String, Object> dataMap) {
if(p.getId() != 0){
dataMap.put("id",p.getId());//id
}else {
dataMap.put("id","无");
}
if(p.getName() != null){
dataMap.put("name",p.getName());//name
}else {
dataMap.put("name","无");
}
if(p.getAge() != 0){
dataMap.put("age",p.getAge());//age
}else {
dataMap.put("age","无");
}
}
- java导出 world
- 导出Excel,world
- jsp 导出world
- PowerDesigner 9 如何导出WORLD
- asp.net 从datagrid导出到world
- asp.net gridview导出Excel、World文档
- Jasper6 导出Excle,PDF,World文件
- hello world项目导出及部署
- Hello World! Java
- JAVA 的HELLO WORLD
- Java 101 : Hello World
- java打印 Hello World!
- java版 hello world
- Hello world in Java
- Java linux hellow world
- ZygoteInit to java world
- java hello world!
- Java "Hello World"
- Python3 实现火车票查询工具
- IOS 第一帖关于无法拿到唯一识别码的方法
- eclipse+HBASE开发环境搭建(已实践)
- FileInputStream 相对路径正确识别
- activity和activity之间传递对象,fragment和fragment之间传递对象的方法
- java导出 world
- 增广路算法Ford-Fulkerson
- Facebook的物体分割新框架研究4——MultiPathNet
- 程序员面试金典: 9.2链表 2.6给定有环链表,实现算法返回环路的开头节点
- mysql 预处理
- cef相关
- 记录一个mysql按日期分组统计的查询
- Strtus2 Convention Plugin 配置规则
- 快速排序