/* RxXL_Automation_014.rex */ /* The purpose of this application is to demonstrate the use of ooRexx ActiveX/OLE to automate the opening of the Excel Workbook created with RxXL_Automation_012.rex. In this demonstration we will determine if the contents of a cell is either a value or a formula */ --Clear the screen call SysCls -- Create the Excel object xlobj = .OleObject~New('Excel.Application') /* Turn the visible attribute off - there's nothing to see in this demostration */ xlobj~Visible = .false --Open the existing workbook infile = '.\RxXL_Automation_013.xls' xlobj~WorkBooks~Open(infile) --We need to determine our lastcell (we'll need the constant to do that) xlLastCell = xlobj~GetConstant('xlLastCell') lastcell = xlobj~ActiveCell~SpecialCells(xlLastCell)~Address parse var lastcell '$'max_column'$'max_row --First lets examine the contents of cell A1 - it should have a value row = 1 col = 'A' call Examine_Cell row = 2 col = 'A' call Examine_Cell row = max_row --This should have a formula in it col = 'A' call Examine_Cell --Quit Excel xlobj~Quit exit Examine_Cell: procedure expose xlobj col row cell_value = xlobj~Cells(row,col)~Value cell_formula = xlobj~Cells(row,col)~Formula select when cell_formula = '' then do c = '-> EMPTY <-' cv = '' end when cell_value \= cell_formula then do c = '-> A FORMULA <-' cv = cell_formula end otherwise do c = '-> A VALUE <-' cv = cell_value end end say 'Cell' col||row"'s Contents Are "cv c return