Author Topic: How do I read Excel spreadsheets using Sparx JScript (instead of Sparx VBScript)  (Read 319 times)

BruceTOGAF2

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
I have discovered that ‘Run-time error '-2147417851 (80010105)’’ is a known bug when using Excel+VBA to import Excel spreadsheets into Sparx .   So, I am taking a new approach to importing spreadsheets into Sparx.  Instead of using Excel+VBA to PUSH data into Sparx, I am trying to use a Sparx Jscript to PULL data into Sparx.

Most of my Sparx code is in Sparx EA JScript (not VBScript). I am looking for the Sparx EA JScript equivalent of Sparx VBScript CreateObject( "Excel.Application"). 

Here is a Sparx EA VBScript that provides a user dialogue that successfully opens an Excel spreadsheet and gets ready to read the cells from xlSheet
===============================================================================
filterString = "All Files |*.*|Excel *.xlsx|*.xlsx|Excel *.xls|*.xls|"
filterIndex = 0
flags = 0
WorksheetNo = 1

inputFileName = InvokeFileDialog(filterString, filterIndex, flags)
LOGInfo("Using the Excel Spreadsheet: " & inputFileName)
Set xlApp = CreateObject( "Excel.Application")
Set xlBook = xlApp.Workbooks.Open (inputFileName)
Set xlSheet = xlBook.Worksheets(worksheetNo)
================================================================================

Here is a Sparx EA JScript that provides a user dialogue that successfully identifies the Excel spreadsheet filename but CreateObject( "Excel.Application") produces error "Object expected"
================================================================================
   
var inputFileName = InvokeFileDialog(filterString, filterIndex, flags, InitialDirectory, OpenorSave)

Session.Output(" Importing from file: " + inputFileName);

// The following code produces error "Object expected"
var xlApp = CreateObject( "Excel.Application");

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7737
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
If you search for "CreateObject" + "jscript" you should find an old thread that lists the variations of this command in the different scripting languages.

Geert

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 868
  • Karma: +11/-0
    • View Profile
See "Using COM / ActiveX Objects" on the following user guide page:
http://www.sparxsystems.com/enterprise_architect_user_guide/13.5/automation/script_editors.html

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7737
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller