wordpress hit counter
How to generate Docx file using C++ - C/C++ - Development Tools - OpenXML Developer

How to generate Docx file using C++

Development Tools

Discussions about working with Open XML using a wide range of development tools

How to generate Docx file using C++

  • This post has 4 Replies |
  • 6 Followers
  • 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....

  • Hi Thunga,

    There are two approaches that you can take:

    If you are writing C++ code for Windows 7, you can use the Packaging API, which enables you to use C or C++ to write programs that query and create Open Packaging Conventions (OPC) files (which include Open XML documents).

    If you want a cross-platform approach, you can use libOPC.

    -Eric
  • Thanks, I am also get benefit from your advice. I have completed the 50% work.

     

     

     

     

     

    ---------------------------------------------------------------------------------------------------------------

    Dinar

  • Hi,

    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

Page 1 of 1 (5 items)