Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Delphi
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.
Posted 12-Aug-10 3:04am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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! Poke tongue | ;-P
 
Another point (rereading after posting Blush | :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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 | :confused:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Wink | ;) Wink | ;) Wink | ;)
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.
  Permalink  
Comments
Peter_in_2780 at 13-Aug-10 22:06pm
   
Good to hear. Would you like to mark your question as answered? Cheers, Peter

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 13 Aug 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100