rtf 文件包含奇怪的格式数据,阻止字段合并
我使用 Word 2007 创建了一个 RTF 文件。我想插入可以在稍后阶段解析并与数据库信息合并的合并字段。该文件包含短语“亲爱的[称呼][姓氏]你好吗?”。然后我将[姓氏]部分编辑为[姓氏]。如果我现在查看 rtf 源,它包含大量不需要的字符,如下所示:
亲爱的 [称呼] [}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid6575321 最后}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2040086姓名}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2434881 ]}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2040086 \r\n\par 你好吗?
这意味着当我尝试合并时,[姓氏] 太混乱而无法找到合并。 有谁知道这是怎么回事,以及如何防止 Word 嵌入所有这些不需要的东西? 谢谢。
I created an RTF file using Word 2007. I want to insert merge fields that can be parsed and merged with database info at a later stage. The document contained the phrase 'Dear [salutation] [surname] How are you?'. I then edited the [surname] part to say [lastname]. If I now view the rtf source it contains loads of unwanted characters as follows:
Dear [salutation] [}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid6575321 last}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2040086 name}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2434881 ]}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2040086 \r\n\par How are you?
This means that when I try merging then the [lastname] is too mangled to be found for merging.
Does anyone know what's going on here, and how I can prevent Word from embedding all this unwanted stuff?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后我使用System.Windows.Forms.RichTextBox解决了这个问题,如下:
In the end I used the System.Windows.Forms.RichTextBox to solve the problem, as below:
您可以使用正则表达式来完成此合并过程。我创建了一篇关于如何做到这一点的博客文章。
使用正则表达式将数据库内容合并到富文本格式模板文档
在Github上可以找到用PHP编写的示例:
https://github.com/olekrisek/PHP_RTF_RegExMerge
You can use Regular expression expressions to complete this merge process. I have created a blog post about how this can be done.
Using regular expression to merge database content into Rich Text format template documents
An example written in PHP can be found on Github:
https://github.com/olekrisek/PHP_RTF_RegExMerge