1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > java 根据ftl文件生成word

java 根据ftl文件生成word

时间:2024-03-05 12:55:14

相关推荐

java 根据ftl文件生成word

java 根据ftl文件生成word

public void exportDoc(String path,String name ,Map data){try {//Configuration 用于读取ftl文件Configuration configuration = new Configuration(new Version("2.3.0"));configuration.setDefaultEncoding("utf-8");/*** 以下是两种指定ftl文件所在目录路径的方式,注意这两种方式都是* 指定ftl文件所在目录的路径,而不是ftl文件的路径*///指定路径的第一种方式(根据某个类的相对路径指定)// configuration.setClassForTemplateLoading(this.getClass(), "");//指定路径的第二种方式,我的路径是C:/a.ftlconfiguration.setDirectoryForTemplateLoading(new File(path));//输出文档路径及名称File outFile = new File(path + "/"+ name+ ".doc");//以utf-8的编码读取ftl文件Template template = configuration.getTemplate(name + ".ftl", "utf-8");Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240);template.process(data, out);out.close();} catch (Exception e) {e.printStackTrace();}}

map的格式为key-value形式,ftl文件需要修改的值为${key}

ftl文档:

循环:

<#list lists as list>${list.name}</#list>

判断:

判断需要判空,否则报错

<#if tj?? && tj = '1'><#else></#if>

表格居中显示:

在表格的表头tr中添加:

<w:tr><w:trPr><w:trHeight w:val="250"/><w:jc w:val="center"/></w:trPr></w:tr>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。