There is a "OpenCloseGroup" in FrontEndTokenExecute. It act like toggle. If the selected cell group is open, FrontEndTokenExecute["OpenCloseGroup"] will close cell group. If the selected cell group is closed, FrontEndTokenExecute["OpenCloseGroup"] will open cell group.
But I want a way to explicitly open or close cell group. It is not like FrontEndTokenExecute["SelectionOpenAllGroups"] or
FrontEndTokenExecute["SelectionCloseAllGroups"] which will open or close all sub cell groups in any level. I want open and close one level like the FrontEndTokenExecute["OpenCloseGroup"] does.
Update
The problem is actually equivalent to seeking an efficient way to get the open status of a cell group, then we can use FrontEndTokenExecute["OpenCloseGroup"].
Thanks to Alexey Popkov for many information. I found currently the most reliable way is to NotebookRead cell data to check if it is closed or not. Here is a way
ClearAll[openSelectedCellGroup];
openSelectedCellGroup[nb_NotebookObject]:=Module[{},
If[MatchQ[NotebookRead[nb],Cell[CellGroupData[_,Closed]]],
FrontEndTokenExecute[nb,"OpenCloseGroup"]];
Though NotebookRead seems to be inefficient if the cell group contains large data. However, my experience is that it is still workable. But again, there should better be a more efficient way to check the open-close state of cell group. Hope anyone knows.
Update 2
Alexey Popkov found a way using CurrentValue[cellObj, "CellGroupOpen"]. Now we finally have an efficient tool for explicitly open and close cell groups! Like this function:
ClearAll[openSelectedCellGroup];
openSelectedCellGroup[nb_NotebookObject]:=Module[{},
If[CurrentValue[First@Cells[NotebookSelection[nb]],"CellGroupOpen"]===Closed,
FrontEndTokenExecute[nb,"OpenCloseGroup"]];
See my real applications here


"SelectionOpenAllGroups"and"SelectionCloseAllGroups"? – kglr Jan 03 '22 at 02:46CellGroupis open or not. Here is one way that doesn't take into account that the second argument ofCellGroupDatacan be aDynamicexpression. – Alexey Popkov Jan 03 '22 at 09:38Developer`CellInformationprovides information about every cell in the selectedCellGroup, but no information on whether the group is open or closed. – Alexey Popkov Jan 03 '22 at 10:02CellBoundingBoxwhich theoretically can be used to determine whetherCellGroupis closed or not. But I know nothing about how to work with it. – Alexey Popkov Jan 03 '22 at 10:09ShowGroupOpenerfor the Notebook, and determine the current state of the Opener (but I don't know how). – Alexey Popkov Jan 03 '22 at 10:19NotebookLocateautomatically opens all groups containing located cell. – Alexey Popkov Jan 03 '22 at 10:27NotebookLocate, it is great. But it is also bugged. It only works in the same notebook. I found if I useNotebookLocateto locate inner folding cells in another notebook, it can not automatically open cell group – matheorem Jan 03 '22 at 14:21