mardi 8 février 2011

How to read data from Word file using X++

Try this following job :)

static void FileIO_ReadFromWord(Args _args)
{    
    str         document = "C:\\Demo Edition.docx";
    COM         wordApplication;
    COM         wordDocuments;
    COM         wordDoc;
    COM         range;
    TextBuffer  txt = 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();

    txt.setText(range.text());

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

Happy Daxing!

Aucun commentaire:

Enregistrer un commentaire