freemarker的xml实现编号和列单独循环

freemarker的xml实现编号和列单独循环,第1张

freemarker的xml实现编号和列单独循环
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.Version;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
public class WordTest {

    @Test
    public void exportListWord() throws Exception{
        // 获取合同协议list
        Map dataMap = new HashMap<>(1);
        List list = new ArrayList<>();
        list.add("合同协议1");
        list.add("合同协议2");
        list.add("合同协议3");
        dataMap.put("templateNameList",list);

        Configuration configuration = new Configuration(new Version("2.3.0"));
        configuration.setDefaultEncoding("utf-8");
        configuration.setDirectoryForTemplateLoading(new File("F:\test"));
        File outFile = new File("F:\test\test-gen.doc");
        Template t =  configuration.getTemplate("协议签署确认函.xml","utf-8");
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8),10240);
        t.process(dataMap, out);
        out.close();
    }

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5678269.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存