Is there a shortcut for switching groups in calc

or is a macro possible?

Macro recording did not record anything.

I mean the groups that you can set with F12 on a row, i need a shortcut to switch between the groups.

Unfortunately it isn’t clear to me what you mean by “switch groups”, and also not your usage of “shortcut” since you obviously know the predefined shortcut key F12. (The shortcut for ungrouping is Ctrl+F12.)

You can group based on a single selected cell range either the rows or the columns. The new group will only be created and added to already existing groups if the nesting is clear.

You can ungroup existing groups (either R or C again) starting with the innermost level intersecting with the current selection.

And you can remove all grouping at once.

All these actions are also accessible via .uno: commands and can be recorded.

Only if you want to group/ungroup based on arbitrary CellRange objects (precisely: their addresses) independent of the current selection, you need user-written code. See LibreOffice: XSheetOutline Interface Reference for additional information.

===Editing 1/2 h later===
Well, I may have understood.
Concerning the macro recorder you complain about its not recording anything if yo click a + or a - associated to an outline level.
The macro recorder simply isn’t a “mouse-action-logger” (and also not a key-logger).
In this case you will get the wanted action recorded if you call it via the menu patrh
>Data>Group and Outline>Hide Detail or
>Data>Group and Outline>Show Detail respectively

I want to open and close all defined groups with a shortcut.

View example screen: https://i.imgur.com/VoIDurO.png

E. g. press ALT+1 to open Group 1, ALT+2 to open Group 2, …

Or is it possible to write a macro, that goes line by line and open a group or nested group. Unfortunately, I do not know anything about macros.

There isn’t something like a “Group 2”. The numbers denote for grouping levels, not for specific groups.
Macros for showing all groups up to a given nesting level are simple and any such macro will at the same time hide the groups above the given nesting level. You may associate such macros to shortcut keys.
A macro for toggling, however, seems to be impossible. The API dosn’t give access to the current state concerning outline groups insofar.

Ok thank you!

See also: Unhide all groups that are closed?