- 浏览: 267053 次
- 性别:
- 来自: 合肥
文章分类
最新评论
-
fjyuxuebin:
怎么调用,有调用demo吗?
jquery 异步treeTable树形插件 -
anyone:
非常不错的插件
jquery 异步treeTable树形插件 -
孤心随云:
看起来不错!试一下先!
jquery 异步treeTable树形插件 -
iwq1990512:
最后Java代码,返回的不是json数据吧
jquery 异步treeTable树形插件 -
dengli19881102:
可以把整个代码提供么?
jquery 异步treeTable树形插件
一、模版制作
1 设计 *.fields.xml文件,在此文件中定义好你要填充的参数。
2 RTFTemplate.dot 设计rtf模版文档。注意,最好将rtf模版文档、RTFTemplate.dot设计器、*.fields.xml文件放在统一文件夹下。否则有可能找不到word加载项里的在*.fields.xml里设定的参数。
二、rtf服务类
三、使用
四、注意事项
1 解析生成的rtf文件有可能是乱码,用文本编辑器将rtf模版文件打开,将
\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;替换成\f0\dbch\charset0\fprq2 宋体; 保存
1 设计 *.fields.xml文件,在此文件中定义好你要填充的参数。
<mergefield> <list>false</list> <name>$title</name> <description><![CDATA[]]></description> </mergefield> <mergefield> <list>false</list> <name>$serialNumber</name> <description><![CDATA[]]></description> </mergefield>
2 RTFTemplate.dot 设计rtf模版文档。注意,最好将rtf模版文档、RTFTemplate.dot设计器、*.fields.xml文件放在统一文件夹下。否则有可能找不到word加载项里的在*.fields.xml里设定的参数。
二、rtf服务类
package com.safetys.zjsg.util; import java.io.File; import java.io.FileInputStream; import java.util.Map; import net.sourceforge.rtf.RTFTemplate; import net.sourceforge.rtf.context.RTFContextFieldsReader; import net.sourceforge.rtf.context.RTFContextUtil; import net.sourceforge.rtf.context.RTFXmlFieldsReader; import net.sourceforge.rtf.document.RTFDocument; import net.sourceforge.rtf.document.transformer.config.DigesterTransformerConfig; import net.sourceforge.rtf.document.transformer.config.TransformerConfig; import net.sourceforge.rtf.helper.RTFTemplateBuilder; import net.sourceforge.rtf.template.IContext; import org.springframework.context.ApplicationContext; public class RTFGenerator { private Map<String, Object> contextMap; private RTFTemplate rtfTemplate = null; private File transformerConfigFile = null; private ApplicationContext applicationContext; private String rtfTemplateImpl; private boolean saveTransformedDocument = false; /** * This value allow to group by content when there is PageBreak in order to group by content. */ private int groupByPerPageBreak = -1; /** * Run RTFTemplate for merging rtfSource with the context putted with the method putContext which be must implement. After execution of this method, files rtfSource + ".<rtfTemplateImpl>.rtf" * (RTF template implementation (vmRTFtemplate,...) and rtfSource + ".out.rtf" (RTF final with values of the context) will be generate. * * @param rtfSource * RTF source model. * @throws Exception */ public final void run(String rtfSource, String rtfTarget) throws Exception { File rtfSourceFile = new File(rtfSource); String rtfTransformedDocumentOutput = rtfSource + "." + getRtfTemplateImpl() + ".rtf"; /** * 1. Get RTFtemplate builder */ RTFTemplateBuilder builder = null; if (applicationContext == null) builder = RTFTemplateBuilder.newRTFTemplateBuilder(); else builder = RTFTemplateBuilder.newRTFTemplateBuilder(applicationContext); /** * 2. Get RTFtemplate with Implementation */ this.rtfTemplate = builder.newRTFTemplate(rtfTemplateImpl); this.rtfTemplate.setGroupByPerPageBreak(groupByPerPageBreak); /** * 3. Put default format */ putDefaultFormat(rtfTemplate); /** * 4. Create a common inner context - not required but showing how common context values can be re-used */ IContext ctx = rtfTemplate.getTemplateEngine().newContext(); putGlobalContext(ctx); /** * 5. Set the template */ rtfTemplate.setTemplate(rtfSourceFile); /** * 6. Set Global Context */ rtfTemplate.setGlobalContext(ctx); /** * 7. Set Transformer Config */ if (transformerConfigFile != null) { TransformerConfig transformConfig = DigesterTransformerConfig.getTransformerConfig(new FileInputStream(transformerConfigFile)); rtfTemplate.setTransformerConfig(transformConfig); } /** * 8. Put Context */ putContext(rtfTemplate.getContext()); if (saveTransformedDocument) { RTFDocument transformedDocument = rtfTemplate.transform(); transformedDocument.save(new File(rtfTransformedDocumentOutput)); } /** * 9. Merge template and context */ rtfTemplate.merge(rtfTarget); } /** * This method must be implement by class wich manage your RTF model. Put the context of your model (eg : context("date", new Date()); ) * * @param context * IContext */ protected void putContext(IContext context) { for (String key : contextMap.keySet()) { context.put(key, contextMap.get(key)); } } /** * Return String XML Mergefields used in your context and Bookmarks (for start and end loop) * * @return */ public String getXMLFields() { // XML RTFXmlFieldsReader reader = new RTFXmlFieldsReader(); reader.readContext(rtfTemplate.getContext(), rtfTemplate.getTransformerConfig()); return reader.getXMLFields(); } protected void putDefaultFormat(RTFTemplate template) { } protected void putGlobalContext(IContext context) { } /** * Save XML fields available into file. If force parameter is false, the file is updated with new context (by keeping just description) otherwise the file is crushed with new context. * * @param filename * @throws Exception */ public void saveXmlFields(String filename, boolean force) throws Exception { RTFContextFieldsReader reader = new RTFContextFieldsReader(); reader.readContext(rtfTemplate.getContext(), rtfTemplate.getTransformerConfig()); RTFContextUtil.saveXmlFields(filename, reader.getContextFields(), force); } public void setTransformerConfigFile(String transformerConfig) { setTransformerConfigFile(new File(transformerConfig)); } public void setTransformerConfigFile(File transformerConfigFile) { this.transformerConfigFile = transformerConfigFile; } /** * set true if RTF with (velocity, freemarker,... macro) file must be generated and false otherwise. * * @param saveTransformedDocument */ public void saveTransformedDocument(boolean saveTransformedDocument) { this.saveTransformedDocument = saveTransformedDocument; } public String getRtfTemplateImpl() { if (rtfTemplateImpl == null) { this.rtfTemplateImpl = RTFTemplateBuilder.DEFAULT_VELOCITY_RTFTEMPLATE; } return rtfTemplateImpl; } public void setRtfTemplateImpl(String rtfTemplateImpl) { this.rtfTemplateImpl = rtfTemplateImpl; } protected int getGroupByPerPageBreak() { return groupByPerPageBreak; } /** * This value allow to group by content when there is PageBreak in order to group by content. * * @param groupByPerPageBreak */ protected void setGroupByPerPageBreak(int groupByPerPageBreak) { this.groupByPerPageBreak = groupByPerPageBreak; } protected RTFTemplate getRtfTemplate() { return rtfTemplate; } protected void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } public void setContextMap(Map<String, Object> contextMap) { this.contextMap = contextMap; } }
三、使用
Map<String, Object> contextMap = new HashMap<String, Object>(); contextMap.put("title", title); //标题 contextMap.put("serialNumber",serialNumber); //事故编号 //rtf生成工具 RTFGenerator generator = new RTFGenerator(); generator.setContextMap(contextMap); generator.run(rtfSource, rtfTarget);
四、注意事项
1 解析生成的rtf文件有可能是乱码,用文本编辑器将rtf模版文件打开,将
\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;替换成\f0\dbch\charset0\fprq2 宋体; 保存
- rtftemplate.rar (2 MB)
- 下载次数: 177
评论
1 楼
美味人间
2013-06-04
根本找不到你说的
\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;
这个字符串
\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;
这个字符串
发表评论
-
HtmlParser 解析搜索页面
2011-04-22 13:35 1648package com.safetys.crawler.u ... -
一个简易的Java爬虫程序
2011-04-19 15:00 8906package com.craw; /* 以下 ... -
HtmlParser 访问节点
2011-04-19 14:23 1248package com.htmlparse.test; ... -
汉字转拼音
2011-03-14 14:11 1824package com.yz.util; impor ... -
润乾报表-动态查询
2011-03-01 21:16 3899润乾报表提供宏工作机制,因此利用宏可以可以动态组织sql语 ... -
velocity 入门实例
2010-11-10 23:11 11171 java文件 package com.test; i ... -
为图片加水印
2010-10-31 22:16 846package com.bizoss.trade.util ... -
使用WebSphere DB2连接池
2010-07-28 17:44 1657WebSphere连接池配置有些繁琐,不过网上有很多例子 ... -
在WebSphere中获取配置文件信息
2010-07-26 16:37 2311在WebSphere环境中,因为工程是打成war包传上去的 ... -
文件合并
2010-03-03 22:15 1135package com.test3; /** * 合 ... -
文件拆分
2010-03-03 22:13 1055package com.test3; import ja ... -
java获取项目所在路径
2010-01-31 16:55 3148package com.test2; public ... -
java mysql数据库的备份与还原
2010-01-31 16:21 59921.底层数据库操作封装 package com.db; ... -
java邮件发送
2010-01-31 16:11 91711.邮件信息封装bean package com.mail ... -
quartz web定时应用
2010-01-31 16:02 14881.web.xml配置 <servlet> ... -
Lucene为数据库建立索引
2010-01-31 15:50 1739package com.lucenedemo; impo ...
相关推荐
rtfTemplate
核心java类 博文链接:https://3ge.iteye.com/blog/1883818
NULL 博文链接:https://hnhhshun-126-com.iteye.com/blog/713411
RTFTemplate 是 RTF 引擎(RTF 到 RTF),它通过将模板 RTF(模型 RTF)与 JAVA 对象(上下文)合并来生成 ... RTFTemplate 使用 Velocity 将模板与对象合并。 可以使用 MERGEFIELD 和 BOO 使用 MS Word 设计 RTF 模板
基于velocity,freemaker操作RTF,生成RTF,是一个比较灵活的工具,可以将生成RTF转换成word达到生成word的效果,其实RTF格式基本上现在的办公软件都能兼容.