Author Topic: Opening/importing a MS-Word document in Sparx Jscript  (Read 122 times)

BruceTOGAF2

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Opening/importing a MS-Word document in Sparx Jscript
« 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'

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7752
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Opening/importing a MS-Word document in Sparx Jscript
« Reply #1 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

BruceTOGAF2

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
Re: Opening/importing a MS-Word document in Sparx Jscript
« Reply #2 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