|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
One of the automation tasks that I need to perform in an app of ours is to import RTF texts (taken from rich tect controls) and auto-detect hyperlinks therein.
Up until Word 2003 I accomplished this by using a Word doc's IDataObject interface to get the formatted RTF text in, and then to run the text through a Range object's AutoFormat method. Prior to calling AutoFormat, I set the AutoFormatPreserveStyles and AutoFormatReplaceHyperlinks properties to TRUE, and all other auto-formatting properties to FALSE. This worked fine and had the desired result.
Now, with Word 2007 I find the AutoFormat method actually removes *all* formatting from the text (but it does still auto-detect hyperlinks properly). How can I fix this? All help will be much appreciated.
-- Regards, Steve.
|
|
Hello Steve,
Is there the possibility you can build a zip that has an installable demo of how to get the contents of a rich text control and manipulate its contents within a range object. The zip can include a text document as to how to reproduce the successful demo using Word 2003, and then how to demonstrate the problem with Word 2007.
Without a working demonstration it is hard for anyone to help - as you may have noticed. The only comment I can add without such a demo is that the RTF control added through the Controls group of Word 2007 isn't the same one you have used in the past. Its contents are saved as an xml file in the packaged components that are among the multiple xml files which are part of a Word 2007 document.
You can attach the zip to this thread.
Regards, Chris Jensen [MS]
|
|
Hi Steve
Have you seen a reply from Chris Jensen (MSFT) in the group where you originally posted your question?
From: chrisjen[ at ]online.microsoft.com (Chris Jensen [MS]) Date: Mon, 14 Aug 2006 20:57:02 GMT Subject: RE: Word 2007 AutoFormat Newsgroups: microsoft.public.officedev
Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005) http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
|
|
No, sorry Cindy, I haven't. I've been on vacation and just returned. Thanks for the pointer - I'll take a look now.
-- Regards, Steve.
|
|
Hi Chris,
I can work up a demo for you (incl. a working exe, naturally), but all my code is actually in Delphi 6. Will this be useful to you?
That said, my code does not use RTF controls. What I do is this:
1. Create two Word docs through automation. The first - doc1, say - is the document I create piecemeal. This is constructed by adding and formatting text, pictures, etc., purely by using Word automation, but I also need to insert formatted text at various stages, where the formatted text originates in RTF (created by another app of ours). The second document - doc2, say - is used for getting the RTF into Word and auto-detecting URLs.
2. When I need to append the RTF source to doc1 I first get it into doc2 by using an IDataObject instance, create a range covers the text (this is in fact simply the Document property) and then run it through the AutoFormat method, after first setting only the AutoFormatPreserveStyles and AutoFormatReplaceHyperlinks properties to true.
3. Finally, I copy the doc2 content to the end of doc1, then clear out doc2 ready for the next RTF.
This works perfectly for all of Word 2000 - 2003, but in Word 2007 the RTF text loses all formatting (except for the auto-detected URLs). With Word 2007, if I omit the AutoFormat call on doc2 then the RTF enters doc2 correctly via the IDataObject interface, and appears exactly as it should when copied to doc1 (missing the hyperlinks, of course). The issue is definitely with the implementation of AutoFormat in Word 2007, as any call to it results in all character and paragraph formatting being lost.
In fact, I can demonstrate the problem by simplifying all of the above: just use automation to load some formatted text into a Word 2007 doc (it doesn't matter where the text comes from - just loading an already-created Word 2007 doc will do), then select it into a range and call AutoFormat. All formatting is lost.
-- Regards, Steve.
|
|
Hi Chris,
On further investigation, I believe I have narrowed down the issue ... it seems the AutoFormat method does work after all, but instead changes to the AutoFormatXXX properties of the Options object do not seem to stick. For instance, if I set the AutoFormatPreserveStyles to TRUE and test its value right afterwards it still shows FALSE. The same applies to all other AutoFormatXXX properties, as far as I can see.
Then when I call the document's AutoFormat method, it seems to take property values from whatever the user has set via the Word 2007 GUI, rather than I set programmatically.
This would appear to be a nasty bug in Word 2007, unless of course there's some changed behaviour I need to know about that affects whether the AutoFormatXXX properties can be changed...
-- Regards, Steve.
|
|
------=_NextPart_0001_45DFFC18 Content-Type: text/plain Content-Transfer-Encoding: 7bit
Hello Steve,
Thanks for working with your issue and suggesting ways I can duplicate it. You may find that the Beta2 Technical Refresh version of Word does what you expect. That should be available soon. The attached code sample reset the Word Options Proofing AutoFormat settings to "checked" after they were unchecked through the User Interface.
Look for the news that Beta 2TR is available. When it is, please try your application again.
Regards, Chris Jensen ------=_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art_0001_45DFFC18--
|
|
Hi Chris,
Many thanks for that. I'll try the B2TR when it appears. Now, I understand you can't commit to a date, but by 'soon' are we talking days, or maybe weeks?
-- Regards, Steve.
|
|
Chris,
I can confirm that the B2TR does indeed resolve this issue, thanks. Unfortunately, it introduces a whole raft of new issues. I'll post about those separately.
-- Regards, Steve.
|
|
|