Hi,
In our VSTO document-level add-in we have to reliably store the contents of RichText ContentControls in a persistable form, for later restoration in its original form.
As the documentation of both Interop and VBA APIs seems to tell, this should be possible by using the content's OpenXML form: Retrieving it with ContentControl.Range.WordOpenXML, and restoring it with ContentControl.Range.InsertXML.
This works in many cases, but fails in other ones, see below.
Does anybody know if there is a better, really reliable(!) way of saving and restoring the contents? Or can you tell us how to work around the current odd behaviour which from our point of view are bugs?
Since official Microsoft support told us that they do not deal with Office API issues I hope that also someone from Microsoft's Office development reads this ...
Thanks in advance,
J.K
What I have tried:
Three examples of unreliability:
(1) A RichText ContentControl ("CC") containing a single paragraph including the terminating paragraph break: The retrieved WordOpenXML is equal to the one taken from a CC containing a single paragraph without the paragraph break. The result is not surprising: In both cases no paragraph break is restored after Range.Insert. In other words: WordOpenXML failed to extract the correct XML in the case where the original contained the break.
(2) A CC containing a single image (and nothing else) is restored without the image, i.e. different from the original. If it contains anything more than the image, there is no such problem.
(3) Examples 1 and 2 apply if the page header section has never been visited. At least in VBA - I haven't checked it in depth with VSTO/interop - the behaviour changes drastically once a page header has been visited. Only visited, nothing more! The restored contents then contains an additional final paragraph break. So if you save and restore it three times, you'll end up with three paragraph breaks which were not present in the original contents. This weird behaviour cannot even be stopped with saving and re-opening the document...