Using Excel with VisualWorks
This morning I did a screencast on using Excel with VisualWorks; I thought a simple walkthrough might be handy as well. The first thing you need to do after starting VW is pull up the Parcel Manager, select "OS-Windows" on the left, and "COM-All" on the right. Right click and load:
Next, close that window, and in a workspace, add this little script. Once you try it out, you can experiment on your own - and use the "Browse Automation Classes" option under the COM menu in the Launcher to explore the interfaces available to you:
"Start Excel, get dispatch driver" excel := COMDispatchDriver createObject: 'Excel.Application'. "Open Excel visibly" excel setVisible: true. excel getWorkbooks Add. sheet := excel getActiveSheet. "Write some data" (excel getRange: 'A1') setValue: 'Name'. (excel getRange: 'A2') setValue: 'Fred Flintstone'. (excel getRange: 'A1:A2') getFont setBold: true. "Read a cell" (excel getRange: 'A1') getValue. "Copy Cells" (excel getRange: 'A1:A2') Select. excel setCutCopyMode: false. excel getSelection Copy. Transcript show: Screen default getExternalSelection.
That code creates a dispatch driver, and then calls various COM APIs exposed by Excel. You'll see a few dialogs like this pop up as you execute that, as the message sends are going to COM, not Smalltalk - and thus, they don't exist in the image:
Just use the "proceed" button to dismiss those. Once you've executed all the code, you should see something like this:
Which should be Excel with the data you entered highlighted, and the copied data sitting in the Transcript, where we printed it. That's it - you're now working with Excel from VW. Go ahead and use the automation browser to explore the full API set.
Technorati Tags: visualworks, excel, com