FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


Excel COM : selecting a cell and recover sheet name

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
Tonton Luc



FRANCE (Le Touquet)
Joined: 16 Oct 2001
Posts: 1548

PostPosted: 19 Sep 2017 7:44    Post subject: Excel COM : selecting a cell and recover sheet name Reply with quote

Hi,

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

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 ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum