预览加载中,请您耐心等待几秒...
1/8
2/8
3/8
4/8
5/8
6/8
7/8
8/8

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第一步: 将事先准备的word文档另存为xml格式 第二步: 利用foxe_CHS打开xml 可以按F8进行排版,找到左侧w:tbl节点,找到需要填充数据的地方,用freemarker标记 依次类推,找到所有需要填充数据的地方,用freemarker标记,填充这些位置,不过这样的话,只能针对单行数据显示,要想多行显示数据,标记这个地方还需要做些工作, 如上,准备工作也基本做好 第三步: 开始正式的demo。 首先你要有这些:freemarker的开源包,如果没有,可以网上下载一个 importfreemarker.template.Configuration; importfreemarker.template.Template; importfreemarker.template.TemplateException; 接下来这么做: 目录 packagecom.test.freemarker.report; importjava.io.BufferedWriter; importjava.io.File; importjava.io.FileOutputStream; importjava.io.IOException; importjava.io.OutputStreamWriter; importjava.io.Writer; importjava.util.ArrayList; importjava.util.HashMap; importjava.util.List; importjava.util.Map; importfreemarker.template.Configuration; importfreemarker.template.Template; importfreemarker.template.TemplateException; publicclassDocumentHandler{ privateConfigurationconfiguration=null; publicDocumentHandler(){ configuration=newConfiguration(); configuration.setDefaultEncoding("utf-8"); } publicvoidcreateDoc(){ //要填入模本的数据文件 MapdataMap=newHashMap(); getData(dataMap); //设置模本装置方法和路径,FreeMarker支持多种模板装载方法。可以重servlet,classpath,数据库装载, //这里我们的模板是放在com.havenliu.document.template包下面 configuration.setClassForTemplateLoading(this.getClass(), "/com/test/freemarker/report"); Templatet=null; try{ //test.ftl为要装载的模板 t=configuration.getTemplate("test.xml"); t.setEncoding("utf-8"); }catch(IOExceptione){ e.printStackTrace(); } //输出文档路径及名称 FileoutFile=newFile("E:/test.doc"); Writerout=null; try{ out=newBufferedWriter(newOutputStreamWriter( newFileOutputStream(outFile),"utf-8")); }catch(Exceptione1){ e1.printStackTrace(); } try{ t.process(dataMap,out); out.close(); }catch(TemplateExceptione){ e.printStackTrace(); }catch(IOExceptione){ e.printStackTrace(); } } /** * *注意dataMap里存放的数据Key值要与模板中的参数相对应 * * * *@paramdataMap * */ privatevoidgetData(MapdataMap){ dataMap.put("title_name"