Hi there, I've come across a problem, I can't solve on my own just by googeling it. So I hope someone here can help me with it.
What I'm trying to do: I'm trying to load the XML-Representation(WordML) from an OLE-Object, modify it and then load it back into the OLE-Object and finally display it to the User. And I want to do this in C++
What I already managed to do: I was able to load the XML via ActiveDocument->Range()->GetXML(false); I parsed the structure and modified it. (Replaced docvariables with their newly calculated values) I loaded it back into the OLE-Object via ActiveDocument->Range()->InsertXML(xml); And I displayed it to the user with Word.
Where the problem is? The Document, I'm parsing, not only contains docvariables, but also conditional form elements(IF). The precalculated results are also part of the XML (They follow the <w:fldChar w:fldCharType="seperate"> -Tag). If I don't replace them, then there will be still displayed the old value. If I simply omit this block, nothing is displayed. The "w:dirty" attribute, which tells Word to recalculate this fields result, is only working when reading the XML from a file, but when using Range()->InsertXML() it's completely ignored. If I call ActiveDocument->GetFields()->Update(); after inserting the XML, it seems that the XML hasn't been parsed yet and all docvariables are replaced by their old values.
Here is an example field code:
{IF "{ DOCVARIABLE docVar}" <> "-1" "{ DOCVARIABLE docVar}" ""}
And here is, how the corresponding XML looks like, after my program set the values of the DOCVARIABLE.
<w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="begin"/></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText> IF "</w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="begin"/></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText> DOCVARIABLE docVar </w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="separate"/></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText>parsed_docVar</w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="end"/> </w:r><w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText>" <> "-1" "</w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="begin"/></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText> DOCVARIABLE docVar </w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="separate"/></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText>parsed_docVar</w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="end"/></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:instrText>" ""</w:instrText></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="separate"/></w:r> <w:r><w:rPr><w:noProof/><w:sz w:val="24"/></w:rPr><w:t><< docVar >></w:t></w:r> <w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="end"/></w:r>
Where
<w:r><w:rPr><w:sz w:val="24"/></w:rPr><w:fldChar w:fldCharType="separate"/></w:r> <w:r><w:rPr><w:noProof/><w:sz w:val="24"/></w:rPr><w:t><< docVar >></w:t></w:r>
I'll be really happy if someone knows a way to do, what I'm trying to do :)
Thanks a lot.