Wednesday, 15 July 2015

X++ CODE TO READ WORD DOCUMENT into AX 2012

Below is the job to read text from Word document to AX 2012

static void ReadFromWord(Args _args)
{     
    str         document = "D:\\Demo Edition.doc"; //path were the word document is situated
    COM         wordApplication;
    COM         wordDocuments;
    COM         wordDoc;
    COM         range;
    TextBuffer  txtBuff = new TextBuffer();

    // Create instance of Word application
    wordApplication = new COM("Word.Application");

    // Get documents property
    wordDocuments = wordApplication.Documents();

    // Add document that you want to read
    wordDoc = wordDocuments.add(document);
    range = wordDoc.range();

    txtBuff .setText(range.text());

    // to replace carriage return with newline char
    txtBuff .replace('\r', '\n');   
   
    info(txtBuff .getText());
}

No comments:

Post a Comment