Excel COM : selecting a cell and recover sheet name

Discussions related to Visual Prolog
Post Reply
User avatar
Tonton Luc
VIP Member
Posts: 800
Joined: 16 Oct 2001 23:01

Excel COM : selecting a cell and recover sheet name

Post by Tonton Luc » 19 Sep 2017 7:44

Hi,

Here is my following VP 7.3 code and all works fine.

Code: Select all

facts excel:comDispInterface:=erroneous. workbooks:comDispInterface:=erroneous. feuilles:comDispInterface:=erroneous. selection_excel:comDispInterface:=erroneous. cellule:comDispInterface:=erroneous.   clauses     onFileOpen(_Source, _MenuTag):-         if string(Excel) = registry::getValue(registry::classesRoot,@"\Excel.Application\CLSID","") then             mainExe::getFileName(Path,_),             CLSID = guid::toNativeGuid(Excel),             IUnknown = comCreation::createInstance(CLSID, iDispatch::iid),             IDispatchExcel = uncheckedConvert(iDispatch,IUnknown),             excel := comDispInterface::new(IDispatchExcel),             excel:setProperty("Visible", comDomains::boolean(true)),                         comDomains::iDispatch(IDispatchWorkbooks) == excel:getProperty("Workbooks"),             workbooks := comDispInterface::new(IDispatchWorkbooks),             workbooks:invokeMethod("Add",[comDomains::integer(1)]), % create a new Workbook with 1 sheet                         comDomains::iDispatch(IDispatchWorkSheets) == excel:getProperty("WorkSheets"),             feuilles := comDispInterface::new(IDispatchWorkSheets),             feuilles:invokeMethod("Add",[comDomains::null,comDomains::null,comDomains::integer(3)]), % add 3 sheets before the active sheet             Nb_feuilles = feuilles:getProperty("Count"),             note("Nb_feuilles = ",toString(Nb_feuilles)),               comDomains::iDispatch(IDispatchSelection) == excel:getProperty("Selection"),             selection_excel := comDispInterface::new(IDispatchSelection),               comDomains::iDispatch(IDispatchCellule) == selection_excel:getProperty("Cells"),             cellule := comDispInterface::new(IDispatchCellule),             cellule:setProperty("Value",comDomains::real(2.27)),             note(tostring(selection_excel:getProperty("Row")))                     end if,         !.     onFileOpen(_Source, _MenuTag).
1) how to select a cell ?

2) how to recover the active sheet name ?

3) how to add a sheet AFTER the active sheet ?

Post Reply