Hello Jan,
As you said, ActiveDocument.ContentControls(1).XMLMapping.SetMapping
strXPath is able to automatically map the Text of ContentControl to the
value of a custom XML node:
Text of ContentControl ? Value of XML node.
But it seems that your request is to add a value converter between the map:
Text of ContentControl ? Value Converter ? Value of XML node.
For instance, if Value of Xml node is "111", you expect Text of
ContentControl could be "AAA" because the Value Converter converts "111" to
"AAA", and vice versa. Am I correct?
I do not think the current version of Office is able to do it with
XMLMapping automatically. But I believe we could do it manually. As
illustrated in my last reply, we could capture the ContentControlOnEnter
event to load and convert data from xml, and capture the
ContentControlOnExit event to convert and save text into xml.
Now, for your question about how to load and save the custom xml packed in
the document file (e.g. docx), here are two approaches for your reference.
Approach 1. Use CustomXMLPart object
After the custom xml is added into the ActiveDocument.CustomXMLParts
collection (
http://msdn2.microsoft.com/en-us/library/aa433523.aspx), we
could get its GUID (
http://msdn2.microsoft.com/en-us/library/aa433640) and
retrieve the CustomXMLPart by using CustomXMLParts.SelectByID method
(
http://msdn2.microsoft.com/en-us/library/aa433526.aspx) in the next open.
CustomXMLPart object contains methods "SelectNodes"
(
http://msdn2.microsoft.com/en-us/library/aa433524.aspx),
"SelectSingleNode" (
http://msdn2.microsoft.com/en-us/library/aa433525.aspx)
which allows you to access the XML nodes and then get/set their values.
Approach 2. If you do not want to add the XML to CustomXMLParts collection,
but just pack the xml into docx, we could use ZipFile class of ICSharpCode
(
http://www.icsharpcode.net/OpenSource/SharpZipLib) and find the entry of
the xml file. As long as we get the steam of the xml, we could use
XmlDocument class to operate on it. Please refer to the function
ReadDocumentXml() in the codeproject article:
http://www.codeproject.com/office/ExtractTextFromDOCXs.asp
As for your second question,
By the way, as we were talking about the content control custom UI, is there
a way to define my own properties to set? (like the "Display the date like
this:" one)
Although Office provide a way to customize some property of document and
application in docProps\doc.xml and docProps\app.xml if you rename the docx
as zip and extract it, the customization does not include that Property UI
base on my research.
If you have any other concerns or need anything else, please feel free to
let me know.
Sincerely,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.