OLE Automation Method
|
Description
|
---|---|
_COMPUTE_
|
invokes a method supported by the OLE automation server and returns a value
|
_DO_
|
invokes a method supported by the OLE automation server (with no return value)
|
_GET_PROPERTY_
|
retrieves the value of a property exposed by the OLE automation server
|
_GET_REFERENCE_ID_
|
returns the reference identifier of an object provided by the OLE automation server
|
_IN_ERROR_
|
returns an object's ERROR status
|
_NEW_
|
assigns an SCL identifier to an external instance of an OLE automation server
|
_SET_PROPERTY_
|
sets the value of a property exposed by the OLE automation server
|
list=makelist(); /* create the SCL list */ /* Add a Listbox in a worksheet */ call send(worksht, '_COMPUTE_', 'Listboxes', listbox); call send(listbox, '_DO_', 'Add', 20, 50, 40, 100); call send(worksht, '_COMPUTE_', 'Listboxes', 1, listone); /* Fill the Listbox with a range of */ /* values from the worksheet */ call send(listone, '_SET_PROPERTY_', 'ListFillRange', 'A1:A3'); /* Get the contents of the Listbox */ call send(listone, '_GET_PROPERTY_', 'List', list);
Init: /* Initialization */ HostClass = loadclass('sashelp.fsp.hauto'); /* Instantiate the Excel object and make it visible */ call send (Hostclass, '_NEW_', ExcelObj, 0, 'Excel.Application'); call send (ExcelObj, '_SET_PROPERTY_', 'Visible', -1); /* Get the Workbook Object, add a new Sheet and get the Sheet object */ call send (ExcelObj, '_GET_PROPERTY_', 'Workbooks', WkBkObj); call send (WkBkObj, '_DO_', 'Add'); call send (ExcelObj, '_GET_PROPERTY_', 'ActiveSheet', WkShtObj); dcl char names{3,2) = ('Lucy', 'Ricky', 'Julliette', 'Romeo', 'Elizabeth', 'Richard'); /* Set the range to be A1:A4 and fill that range with names */ call send(WkShtObj, '_COMPUTE_', 'Range', 'A1', 'B3', RangeObj); call send(RangeObj, '_SET_PROPERTY_', 'Value', names); dcl num primes{2,4} = ( 1, 3, 5, 7, 11, 13, 17, 23); /* Set the range to be A5:D6 and fill that range with ints values */ call send(WkShtObj, '_COMPUTE_', 'Range', 'A5', 'D6', RangeObj); call send(RangeObj, '_SET_PROPERTY_', 'Value', primes); dcl char totals{1,4} = ('=SUM(A5,A6)', '=SUM(B5,B6)', '=SUM(C5,C6)', '=SUM(D5,D6)'); /* Set the range to be A1:A4 and fill that range with totals */ call send(WkShtObj, '_COMPUTE_', 'Range', 'A7', 'D7', RangeObj); call send(RangeObj, '_SET_PROPERTY_', 'Value', totals); dcl char vals{7,4}; call send(WkShtObj, '_COMPUTE_', 'Range', 'A5', 'D7', RangeObj); call send(RangeObj, '_GET_PROPERTY_', 'Value', vals); return;
call notify('sascombo', '_set_property_', '', 'An excellent choice');is equivalent to:
call notify ('sascombo', '_set_property_', 'Text', 'An excellent choice');
call send(chart, '_DO_', 'ChartWizard', hcell, -4098, 6, 1, 0, 0, 1, "Automation at work!", 'Column', 'Value', 'Row');
call send(chart, '_DO_', 'ChartWizard', hcell, ., ., ., ., ., ., "Automation at work!", ., ., .);
hostcl=loadclass('sashelp.fsp.hauto');
oleauto
and associates the object with
Microsoft Excel (which has the identifier Excel.Application
in
the Windows registry) on the local machine. call send(hostcl, '_NEW_', oleauto, 0, 'Excel.Application');
Init: HostClass = loadclass('sashelp.fsp.hauto'); ExcelObj = 0; /* Define the machine name and put it in a list */ machineName = '\\Aladdin'; inslist = makelist(); attrlist = makelist (); rc = insertc (attrlist, machineName, -1, 'remoteServer'); rc = insertl (inslist, attrlist, -1, '_ATTRS_'); /* Instantiate the Excel object and make it visible */ call send (HostClass, '_NEW_',ExcelObj, inslist, 'Excel.Application'); call send (ExcelObj, '_SET_PROPERTY_', 'Visible', -1); return;
SAS OLE Objects
|
SAS OLE Automation Objects
|
---|---|
Are derived from the Widget class.
|
Are derived from the Object class.
|
Have a visual component (the object that you place in the FRAME entry).
|
Have no visual component within the FRAME entry.
|
Are created by placing the object in a region in the FRAME entry (using drag and drop).
|
Are created by using
the LOADCLASS statement and the _NEW_ method in SCL.
|
Represent the specific type of data object (which you choose) supported by the OLE
server.
|
Represent the top-level application object supported by the OLE server, which you
then might use to open objects of specific data types.
|
Enable you to call methods with CALL NOTIFY by passing in the object name from the
FRAME entry.
|
Require you to call methods with CALL SEND, passing in the object identifier returned
by the _NEW_, _GET_PROPERTY_, or _COMPUTE_ methods.
|
Action
|
SCL Code
|
---|---|
Load an instance of the OLE Automation class and invoke Excel. Set the object to
Visible, so you can see the automation in progress.
|
LAUNCHXL: hostcl = loadclass('sashelp.fsp.hauto'); call send(hostcl, '_NEW_', excelobj, 0, 'Excel.Application'); call send(excelobj, '_SET_PROPERTY_', 'Visible', 'True'); return; |
Get the identifier for
the current Workbooks property and add a worksheet. Then get the
identifier for the new worksheet.
|
CREATEWS: call send(excelobj, '_GET_PROPERTY_', 'Workbooks', wbsobj); call send(wbsobj, '_DO_', 'Add' ); call send(excelobj, '_GET_PROPERTY_', 'ActiveSheet', wsobj); |
Open a SAS data set.
|
dsid=open('sasuser.class','i'); call set(dsid); rc=fetch(dsid); nvar=attrn(dsid, 'NVARS'); nobs=attrn(dsid, 'NOBS'); |
Traverse the data set
and populate the cells of the Excel worksheet with its data, row
by row.
|
do col=1 to nvar; call send(wsobj, '_COMPUTE_', 'Cells',1,col,retcell); var=varname(dsid,col); call send(retcell,'_SET_PROPERTY_', 'Value',var); end; do while (rc ne -1); do row = 1 to nobs; do col = 1 to nvar; r=row+1; call send (wsobj, '_COMPUTE_', 'Cells', r ,col,retcell); if vartype(dsid,col) eq 'N' then do; varn=getvarn(dsid,col); call send(retcell, '_SET_PROPERTY_', 'Value' ,varn); end; else do; varc=getvarc(dsid,col); call send(retcell, '_SET_PROPERTY_', 'Value' ,varc); end; end; rc=fetch(dsid); end; end; dsid=close(dsid); return; |
Close the worksheet and end the Excel session. The _TERM_ method deletes the OLE
automation instance.
|
QUITXL: call send(excelobj,'_GET_PROPERTY_', 'ActiveWorkbook', awbobj); call send(awbobj, '_DO_', 'Close', 'False'); call send(excelobj, '_DO_', 'Quit'); call send(excelobj, '_TERM_'); return; |
Visual Basic Code
|
OLE Automation in SCL
|
---|---|
Launch
Excel and make it visible
Set excelobj = CreateObject("Excel.Application") excelobj.Visible = True |
hostcl = loadclass('sashelp.fsp.hauto'); call send ( hostcl, '_NEW_', excelobj, 0, 'Excel.Application'); call send (excelobj,'_SET_PROPERTY_', 'Visible','True'); |
Create
a new worksheet
Dim wbsobj, wsobj As Object Set wbsobj = excelobj.Workbooks wbsobj.Add Set wsobj = excelobj.ActiveSheet |
call send(excelobj,'_GET_PROPERTY_', 'Workbooks', wbsobj); call send(wbsobj, '_DO_', 'Add'); call send(excelobj,'_GET_PROPERTY_', 'ActiveSheet', wsobj ); |
Set
the value of a cell
wsobj.Cells(row + 1, col).Value =var |
r=row+1; call send(wsobj,'_COMPUTE_', 'Cells', r, col, retcell); call send(retcell,'_SET_PROPERTY_', 'Value' ,var); |
Close the Excel application object
excelobj.ActiveWorkbook.Close ("False") excelobj.Quit |
call send(excelobj,'_GET_PROPERTY_', 'ActiveWorkbook', awbobj); call send(awbobj, '_DO_', 'Close', 'False'); call send(excelobj,'_DO_', 'Quit'); call send(excelobj,'_TERM_'); |