Поделиться через


HOWTO: Print Word document from X++

You might need to print Word document directly from X++. Here’s a short sample how to do this:

 {
    str     document = "C:\\test.doc";
    COM     wordApplication;
    COM     wordDocuments;
    COM     wordDoc;
    ;

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

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

    // Open document
    wordDoc = wordDocuments.Open(document);

    // Activate the document - this is necessary to print it
    wordDoc.Activate();

    // Print the document
    wordDoc.PrintOut();

    // Close document
    wordDoc.Close();

    // Close Word application
    wordApplication.Quit();
}

Martin F