Ask Your Question

libreOffice calc subtotal in macro [closed]

asked 2017-02-17 03:08:42 +0200

rnorton22508 gravatar image

updated 2020-07-21 05:52:19 +0200

Alex Kemp gravatar image

I am trying to move from excel I need a macro to subtotal but I can only get it to bring up the dialog. What arguments is dispatcher.executeDispatch(document, ".uno:DataSubTotals", ... looking for?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-24 21:39:28.310340

1 Answer

Sort by » oldest newest most voted

answered 2017-02-17 03:51:43 +0200

Ratslinger gravatar image

updated 2017-02-17 04:27:17 +0200

This is one way:

    oFunction = createUnoService("")
    oSheet = ThisComponent.Sheets.getByName("YOUR-SHEET")
    myRange = oSheet.getCellRangeByName( "G41:G42" )
    myRange1 = oSheet.getCellRangeByName( "G31:G32" )
    myRange2 = oSheet.getCellRangeByName( "G36:G36" )
    dim aArgument(3) as variant
    aArgument(0)=1              'Function - "1" is for Average'
    aArgument(1)=myRange        'First Range'
    aArgument(2)=myRange1       'Second Range'
    aArgument(3)=myRange2       'Third Range'
    TotalCount = oFunction.callFunction( "SubTotal", aArgument )

aArguement may be 1, 2 or 3 depending upon the number of ranges involved. Adjust accordingly. Your result is in TotalCount. Also see this post for a list of functions.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-02-17 03:08:42 +0200

Seen: 183 times

Last updated: Feb 17 '17