Sparx Systems Forum

Discussion => Automation Interface, Add-Ins and Tools => Topic started by: BruceTOGAF2 on December 07, 2017, 09:55:04 pm

Title: Opening/importing a MS-Word document in Sparx Jscript
Post by: BruceTOGAF2 on December 07, 2017, 09:55:04 pm
// The following code succesfully opens a CSV file as a worksheet
var xlApp = new ActiveXObject( "Excel.Application");
var xlBook = xlApp.Workbooks.Open (inputFileName);
var xlSheet = xlBook.Worksheets(worksheetNo);
var wsSource = xlSheet;
wsCell = wsSource.Cells(2, 1);

How do I do the same with a Word document?

// The following code fails to open a Word Document
var wordApp = new ActiveXObject( "Word.Application");
// Above line seems to succeed
var wordDoc = wordApp.Open (inputFileName);
// Above line errors out 'Object doesn't support this property or method'


// The following code fails to open a Word Document
var wordApp = new ActiveXObject( "Word.Application");
// Above line seems to succeed
var wordDoc = wordApp.Document.Open (inputFileName);
// Above line errors out 'Document is null or not an object'
Title: Re: Opening/importing a MS-Word document in Sparx Jscript
Post by: Geert Bellekens on December 07, 2017, 10:17:47 pm
Have you tried googling that.
There seems to be loads of results.

One of them (I just copied it, did not verify)

Code: [Select]
function openWord(spath) {
            var pause = 0;
            var wdDialogFileOpen = 80;
            var wdApp = new ActiveXObject("Word.Application");
            wdApp.Visible = 'True';
            var wdDoc = wdApp.Documents;
            wdDoc.Open(spath);
            document.form1.submit();
        }

Geert
Title: Re: Opening/importing a MS-Word document in Sparx Jscript
Post by: BruceTOGAF2 on December 08, 2017, 02:25:56 am
// The following lines open the Word document successfully
var wdObj = new ActiveXObject("Word.Application");
wdObj.Visible = true;
var wdDoc = wdObj.Documents.Open(inputFileName);

Thank you Geert