Hi,
I need help to generate docx using open xml concepts.
I got many sample code on java , .NET, etc...
But i need to generate docx using C++ please can you help me regarding this.
I dont know from where to start....
Thanks, I am also get benefit from your advice. I have completed the 50% work.
---------------------------------------------------------------------------------------------------------------
Dinar
I am trying to replace bookmark in docx with text in c++\cli using open xml concepts.
The below piece of code will get the bookmarks from word and checks if the bookmark is “VERSION” if it is true then it replaces “0000” in docx.
Paragraph ^paragraph = gcnew Paragraph();
Run ^run = gcnew Run();
DocumentFormat::OpenXml::Wordprocessing::Text^ text = gcnew DocumentFormat::OpenXml::Wordprocessing::Text(“0000”);
run->AppendChild(text);
paragraph->AppendChild(run);
IDictionary<String^, BookmarkStart^> ^bookmarkMap =
gcnew Dictionary<String^, BookmarkStart^>();
for each (BookmarkStart ^bookmarkStart in
GlobalObjects::wordDoc->MainDocumentPart->RootElement->Descendants<BookmarkStart^>())
{
if (bookmarkStart->Name->Value == “VERSION”)
bookmarkStart->Parent->InsertAt<Paragraph^>(paragraph,3);
}
The above code works fine for most of the scenario(wherever we insert bookmarks), but few times it fails and I am not able to find the reason.
And if the bookmark is inserted at the starting position of a line then after execution I will be not able to open docx, there will be some errors.
I tried giving the index value as 0 for InserAt method but this will not work.
Please provide me a method for my requirement.
Thanks in advance.
Thunga
I followed your advice correctly and finally I was able to generate Docx file using C++. It has made my tasks easier than before. Thanks a lot for such kind information.
Regards,
Carmest