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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dserp Profile Picture

dserp 4

#2
dekion Profile Picture

dekion 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans