Function Repository Resource:

CellGroupingStatus

Source Notebook

Store and restore the open or closed status for all cell groups in a notebook

Contributed by: Lou D'Andria

ResourceFunction["CellGroupingStatus"][nbobj]

returns the grouping status for every cell group in the given notebook.

ResourceFunction["CellGroupingStatus"][nbobj,{cellobj1,cellobj2,}]

returns the grouping status for every cell group whose heading cell is one of the celli.

ResourceFunction["CellGroupingStatus"][nbobj,{cellobj1status1,cellobj2status2,}]

sets the grouping status for each cell group with the given heading cells.

Details

The status of a cell group is whether it is opened or closed.
ResourceFunction["CellGroupingStatus"][nbobj] returns a list of rules of the form cellobjistatusi, where cellobji refers to the first cell in cell group i, and statusi indicates whether that cell group is open or closed.
Supported values for statusi are Open and Closed, and are taken from the second argument of CellGroupData in the structure of the notebook.
Neither reversed-closed groups nor Dynamic values for statusi are supported yet.
After setting grouping status, ResourceFunction["CellGroupingStatus"][nbobj,{cellobj1status1,}] returns list of objects and statuses which were actually changed by this call.

Examples

Basic Examples (3) 

Get the cell grouping status for every cell group in the current notebook:

In[1]:=
ResourceFunction["CellGroupingStatus"][] // Short
Out[1]=

Get the cell grouping status for the first cell in this notebook:

In[2]:=
ResourceFunction["CellGroupingStatus"][
 EvaluationNotebook[], {Cells[][[1]]}]
Out[2]=

Set the cell grouping status for the first cell in this notebook:

In[3]:=
ResourceFunction["CellGroupingStatus"][
 EvaluationNotebook[], {Cells[][[1]] -> Closed}]
Out[3]=

Scope (3) 

Select a notebook:

In[4]:=
nbobj = ResourceFunction["ClickedNotebook"][]
Out[4]=

Store the open/closed grouping status for every cell group in the notebook:

In[5]:=
grouping = ResourceFunction["CellGroupingStatus"][nbobj];

After opening or closing cell groups in the notebook, restore the stored grouping status:

In[6]:=
ResourceFunction["CellGroupingStatus"][nbobj, grouping];

Version History

  • 1.0.0 – 18 March 2026

Related Resources

License Information