Ask Your Question

libreOffice calc subtotal in macro

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

rnorton22508 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 close merge delete

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
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 19 times

Last updated: Feb 17