OLE Excel storing and retrieving worksheets in form memory (OpenInsight 32-Bit)
At 19 AUG 2010 11:39:16PM Chee Onn Wu wrote:
Hi, i'm looking for a proper method when setting up the cells from the created worksheet. But the program that passing the data into my OLE coding is separated program, i want to call the OLE program to setup and insert set of data into the worksheet's cells, sorry for my terrible explanation,
Here is my coding to setting up the excel application,workbooks and worksheets: START: XLAPP = OLECREATEINSTANCE("EXCEL.APPLICATION") ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "MS EXCEL Not Found"); STOP OLEPUTPROPERTY(XLAPP, 'VISIBLE', XLSHEETVISIBLE) ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "Cannot Set EXCEL Visible"); STOP XLWORKBOOKS=OLEGETPROPERTY(XLAPP, "WORKBOOKS") ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "Cannot Setup WORKBOOKS"); STOP XLWKB = OLECALLMETHOD(XLWORKBOOKS,"ADD") ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "Cannot Create New WORKBOOK"); STOP XLSHT = OLEGETPROPERTY(XLWKB, "WORKSHEETS") ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "Cannot Setup WORKSHEETS"); STOP *CALL SET_PROPERTY(@WINDOW,"@Z_XLSHT",XLSHT) *I wanted to store XLSHT into the form memory and retrieve back RETURN : : : The worksheet only need to create once and repeadtedly setup the cells in the same worksheet:
LIST:
CELLS=OLEGETPROPERTY(XLSHT, 'CELLS', EXCEL_ROW,EXCEL_COL)
ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "Cannot Setup CELL for Data."); STOP
OLEPUTPROPERTY(CELLS, 'VALUE', MYDATA)
ERR=OLESTATUS(); IF ERR THEN CALL MSG(@WINDOW, "Cannot read Data for cell R":EXCEL_ROW:"C":EXCEL_COL:"."); STOP
RETURN
So, here is my question, is there anyway to store the XLSHT temporary (form memory)? It gave me error:ENG0061 msg, or any advise to get this to works? Any comments and advises would be very appreaciated. Thanks in advance.
At 20 AUG 2010 08:49AM Bob Carten wrote:
]] there anyway to store the XLSHT temporary (form memory)?
Yes.
Create a common variable. Then, in your program, test to see if the sheet is initialised, else runt the section of code that creates it. You cannot test an variable directly ( you will get ENG0061), so you need another way to see if the sheet exists. I like to use a flag ( installed$) to see if I have created the spreadsheet. Another approach is to test for a property that will never be null, for example installed=( oleGetProperty(xlsht, 'Name') ne '' )
common /xlwbcommon/installed%, XLAPP%,XLSHT%
if assigned(installed%) else installed%='
if installed% else
GoSub Startend
At 23 AUG 2010 12:07AM Chee Onn Wu wrote:
Hi Bob,
Its works! I just declare the common variable, bind the XLSHT into XLSHT% common variable in my START() and then use the XLSHT% in my LIST(). Its simple!
Thank you so much.