From: JulioBP \(Uady, desde casa\)

Subject: Ole Lisp facility, more specific

Date: 2003-5-30 10:10


> Good day Mr Gradwohl and Mr. Wolf > > Gradwohl > Thus, I have > Gradwohl > no code examples regarding ways to manipulate Excel objects
from
> Gradwohl > Lisp. > > I do have something to share with you. I rised the question a couple of > weeks > ago since I'm making a lisp-based Montecarlo CPM simulation program. > I need to send the results to any office application for further analysis.
I
> don't mean > that it cannot be done in ACL, but my colegues want a more familiar > approach, > with fancy graphics and so forth, available in off-the-shelf software.
I've
> being > tinkering with ACL, modifying the internet explorer ole sample code for > comunicating with Excel, and came up with following code: > > USER(6): (defparameter Excel-classid > (ole:unique-guid > "{00024500-0000-0000-C000-000000000046}")) > > USER(7): (block test > (ole:with-open-registry-key > (Excel-reg ole:rkey-classes-root > `("CLSID" ,(ole:guid-name Excel-classid)) > :error-return nil) > (when (null Excel-reg) > (format t "Sorry, no excel on this system~2%") > (return-from test nil))) > (ole:start-ole) > (setf Excel-tool > (ole:ask-for-autotool > Excel-classid > ole:CLSCTX_LOCAL_SERVER)) > (setf (ole::auto-getf Excel-tool :visible) t)) > > The last code loads an empty instance of Excel application (no workbooks). > All methods and properties of the application are available, so things > like the following behave as expected: > > ;; Executes the openfile dialog box, > ;; although it doesn't open > ;; the workbook when a file is > ;; is selected: > USER(8): (ole:auto-method excel-tool > :GetOpenFilename) > "C:\\Usr\\JulioBP\\Course\\weather.xls" > > ;; Gets the value of the app: > USER(9): (ole:auto-getf excel-tool :value) > "Microsoft Excel" > > ;; Gets the pointer to the workbooks collection > ;; I think.... > USER(10): (ole:auto-getf excel-tool :workbooks) > #<IDISPATCH-CLIENT:6617c> > > And things like that. Everything seems to behave as expected from > the example. But since I'm used to Visual Basic, I presumed > that calling a subclass of the application, like the "Workbooks"
collection
> for instance, and adding a new book might be as easy as saying: > > USER(9): (ole:auto-method > (ole:auto-getf excel-tool :workbooks) > :add) > Error: no valid method > > Ok. Maybe I'm to much used to VB, since when an instance of an office > application > is open, all the underlying hierachy should be available. So it seems that
I
> have > to load something else (an extra interface maybe). But from here on I'm > stuck > > Gradwohl > Our main means of manipulating Lisp from Excel was by using the > Gradwohl > command > Gradwohl > lispServer = CreateObject("objectname") > Gradwohl > where objectname is the name of the OLE server as it appears in > Gradwohl > the Registry. > > Ok. so making the backward analogy, I should look for > an object registered as "workbook" (or it's GUID), and setf > it to a variable, just as I did with application, might create > a new book, but there is a little problem. there is no > "workbook" class in the registry, perhaps because it's not > registered under that name. The closest thing to it is > "ExelWorksheet" > > USER(10): (defparameter xl-WSheet-classid > (ole:unique-guid "{00030000-0000-0000-C000-000000000046}")) > XL-WSHEET-CLASSID > > > USER(11): (setf xl-WSheet > (ole:ask-for-autotool > xl-WSheet-classid > ole:CLSCTX_LOCAL_SERVER)) > #<OLE:REMOTE-AUTOTOOL @ #x210508aa> > > CG-USER(12): (ole:auto-method > xl-WSheet > :add) > Error: OLE call returned #x80020006 (code: #x6, facilty: #x2) > [condition type: INCOMING-ERROR] > > I think I'm missing something else. Besides, now the error is > getting worst. Any Ideas > > Gradwohl> Please let me know if you need further assistance. > > Don't worry I'll do > ===================== > Dr. Julio R. Baeza Pereyra > Universidad Autónoma de Yucatán > Facultad de Ingeniería. > Av. Industrias no contaminantes s/n > por Periférico Norte. > Mérida, Yucatán, México >