Word Automation-插入文本和RTF [英] Word Automation - Inserting Text and RTF

查看:137
本文介绍了Word Automation-插入文本和RTF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我将Word自动化以创建一个新文档,并从Firebird数据库中的Blob字段构建该文档.一切正常,直到我尝试在保留RTF格式的同时尝试在RTF内容后插入文本.我要尝试的结果可能看起来像这样.

III.3a)是 RTF 格式化的文本.

"III.3a"是来自VarChar字段的纯文本,其余部分是RTF,存储在blob中.当试图使它们都出现在同一行时,RTF似乎正在覆盖纯文本.

我可以用C#或Delphi做到这一点;语言没关系.这是一些带有RTF内容的Delphi代码,已将其读入Delphi TRichEdit组件中. WordDocument是Delphi TWordDocument组件.

WordDocument.Paragraphs.Last.Range.InsertAfter(''III.3a)'');
Rtf.SelectAll;
Rtf.CopyToClipboard;
WordDocument.Paragraphs.Last.Range.Paste;

感谢您的帮助....如果您可以提供一个有效的代码段,我会在您的名字后面命名四个孩子.

Hi All,

I''m automating Word to create a new document where I''m building the document from blob fields within a Firebird database. Everything works fine until I try to insert text followed by RTF content while preserving the RTF formatting. What I''m trying to end up with might look like this.

III.3a) The is the RTF formatted text.

The ''III.3a'' is plain text from a VarChar field but the rest is RTF stored in a blob. When trying to get them both to appear on the same line, the RTF seems to be overwriting the plain text.

I can do this in C# or Delphi; language doesn''t matter. Here''s some Delphi code with the RTF stuff having been read into a Delphi TRichEdit component. WordDocument is a Delphi TWordDocument component.

WordDocument.Paragraphs.Last.Range.InsertAfter(''III.3a) '') ;
Rtf.SelectAll ;
Rtf.CopyToClipboard ;
WordDocument.Paragraphs.Last.Range.Paste ;

Thanks for any help.... If you can provide a working snippet, I''ll name my next 4 children after you.

推荐答案

建议:粘贴VarChar和RTF一起放入TRichEdit中,然后将其一键粘贴.至少您将拥有Delphi IDE对其进行调试! ; P

另一点(发布后重新阅读:-O)听起来像粘贴时在Word中选择了III.3a,所以它是替换而不是插入.有什么方法可以在粘贴之前立即检查在Word中选择的内容吗?如果是III.3a,请在其后放一些东西,然后选择要粘贴的东西.
Suggestion: glue the VarChar and RTF together inside your TRichEdit then paste the lot in one hit. At least you''ll have the Delphi IDE to debug it! ;P

Another point (rereading after posting :-O ) the behaviour sounds like the III.3a is selected in Word when the paste occurs, so it''s a replace rather than insert. Any way of checking what''s selected in Word immediately before pasting? If it''s the III.3a, put something after it and select that for replacement by paste.


感谢您的答复.在III.3a之后插入一些东西是一个很好的建议(我没有尝试过),但是没有用.看来,"WordDocument.Paragraphs.Last.Range.Paste"从该行的开头粘贴,从而覆盖了先前在该行上插入的所有内容.我需要能够在行上粘贴现有文本之后,而这正是我没有弄清楚的. :confused:
Thanks for your reply. Inserting something after the III.3a was an excellent suggestion (one that I hadn''t tried) but didn''t work. It appears that "WordDocument.Paragraphs.Last.Range.Paste" pastes from the beginning of the line overwriting anything previously inserted on that line. I need to be able to paste AFTER existing text on the line and that''s what I''m not figuring out. :confused:


;););)
我知道了!!!我将"WordDocument.Paragraphs.Last.Range.Paste"更改为"WordDocument.Bookmarks.Item(endOfDoc).Range.Paste",其中endOfDoc ="\ endofdoc".现在,它将RTF粘贴到文档的末尾,而不会覆盖之前在行中插入的内容.
;) ;) ;)
I got it!!! I changed "WordDocument.Paragraphs.Last.Range.Paste" to "WordDocument.Bookmarks.Item(endOfDoc).Range.Paste" where endOfDoc = ''\endofdoc''. Now it pastes the RTF at the end of the document without overwriting what been previously inserted on the line.


这篇关于Word Automation-插入文本和RTF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆