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)

Creating word doc using Open XML SDK 2.0

(0) ShareShare
ReportReport
Posted on by

Hi ,

I am unable to write into the document using the open xml sdk 2.0 in Axapata 2009. Here it is sample code am using it to create and write into the document.

    DocumentFormat.OpenXml.Packaging.WordprocessingDocument  wordPackage = null;
    DocumentFormat.OpenXml.Packaging.MainDocumentPart        mainDocumentPart = null;
    DocumentFormat.OpenXml.Wordprocessing.Document           document    = null;
    DocumentFormat.OpenXml.Wordprocessing.Body               body    = null;
    DocumentFormat.OpenXml.Wordprocessing.Paragraph          paragraph   = null;
    DocumentFormat.OpenXml.Wordprocessing.Text               text = new    DocumentFormat.OpenXml.Wordprocessing.Text("Hello world!");
    DocumentFormat.OpenXml.Wordprocessing.Run                run  =  new DocumentFormat.OpenXml.Wordprocessing.Run(text);
    ;
    wordPackage = DocumentFormat.OpenXml.Packaging.WordprocessingDocument::Create(@"C:\TestDocByAppend.docx", DocumentFormat.OpenXml.WordprocessingDocumentType::Document);
    mainDocumentPart = wordPackage.AddMainDocumentPart();
    document = new DocumentFormat.OpenXml.Wordprocessing.Document();
    body = new DocumentFormat.OpenXml.Wordprocessing.Body();
    paragraph = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
    paragraph.Append(run);
    body.Append(paragraph);
    document.Append(body);
    document.Save(mainDocumentPart);
    wordPackage.Close();

The above code just creates the blank document but does not write the text in it. This code works perfectly in the .Net using the visual studio which creates and writes the text in the document. The open xml dll used for both .Net and Axapta is same. Can you please help me out  in how to do this Axapta.? Thanks

*This post is locked for comments

I have the same question (0)
  • Sacha Kircev Profile Picture
    905 on at

     Hi,

     have you tried to add a call to get a permission of type CLRInterop permission just before the

    creation of the "Hello World" text?

    Regards.

  • Community Member Profile Picture
    on at

    Hi,

    Thanks for reply, I have tried adding the CLRInterop permission to the code even then text is not written in the document. And also this  CLRInterop permission is necessary for COM objects . This open XML SDK is  .Net DLL.

    Rgds 

     

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