08-14-2004, 04:22 PM
Excel can be controlled programmatically. Following example displays all selected cells.
Excel programming reference can be found in Excel help. It is not part of default installation, but can be installed later.
;declare Excel type library (use 'Type libraries' dialog in Tools menu)
typelib Excel {00020813-0000-0000-C000-000000000046} 1.2
#opt dispatch 1 ;;call functions through IDispatch::Invoke (may not work otherwise)
;connect to Excel (must be running) and get active sheet
Excel.Application xlApp._getactive
;get selection and number of selected cells
Excel.Range r=xlApp.Selection
int i j ncells=r.Count
;raw display
for i 1 ncells+1
,out r.Item(i)
;display formatted as table. Must be selected 3 columns.
str s s1 s2 s3
for i 1 ncells/3+1
,s1=r.Item(i 1)
,s2=r.Item(i 2)
,s3=r.Item(i 3)
,s.formata("Row %i: %s %s %s[]" i s1 s2 s3)
out s
Excel programming reference can be found in Excel help. It is not part of default installation, but can be installed later.