web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create/Read/Write Word Document using Open XML

(0) ShareShare
ReportReport
Posted on by

Hi there,

I prepare a new Word template and save it as a file .dotx. The template contains bookmark and table with a single row and two columns.

In the AOT, I create a new job and using COM, I add values to the bookmarks and by using while select, I am adding values from table to the left column. Then I generate .docx Word document that includes these values.

Instead of using COM, I would like to use openXML to create Microsoft Word document and add values to the bookmarks and by using while select, add values from table to the left column in the table raw and then, read values from my bookmarks and from the right columns and save it to the AX table.

I find some examples how to read/write data from Microsoft Excel document, but that don't help me. Also for some reason, most of the examples are in C# instead of X++.

Could you advise me or show some example how to do it using openXML and X++?

Thank you.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    Here is a trivial example as a starting point for you:

    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Packaging;
    
    class WordDocReader
    {        
        public static void main(Args _args)
        {     
            str filePath = @"c:\Temp\test.docx";
    
            using (WordprocessingDocument doc = WordprocessingDocument::Open(FilePath, false))
            {
                str bodyText = doc.MainDocumentPart.Document.Body.InnerText;
                info(bodyText);
            }
        }
    }

    By the way, you shouldn't be afraid of examples in C#, it's very similar to X++.

  • Community Member Profile Picture
    on at

    Thanks. So the code read everything between body I assume.  

    (from Open XML SDK productivity tool)

    <w:document>

    <w:body>

    <w:p/>

    </w:body>

    </w:document>

    Could you give me example how to read bookmark name Test?

  • Suggested answer
    Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at

    Look at How to work with bookmarks in Word OpenXML on GitHub. Because it uses generic methods (e.g. Descendants<BookmarkStart>()), it will be much easier if you write this part in C# and merely call it from X++.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/globalsearch/?q=co+to+jest+alba++krzy%C5%BC%C3%B3wka" - Nested quantifier +.