Function Repository Resource:

LargestCellObject

Source Notebook

Select the largest cell by byte count in a notebook

Contributed by: Bob Sandheinrich

ResourceFunction["LargestCellObject"][]

gives the CellObject for the largest cell in the current notebook.

ResourceFunction["LargestCellObject"][nbo]

gives the CellObject for the largest cell in the NotebookObject nbo.

ResourceFunction["LargestCellObject"][{cellobj1,}]

chooses the largest cell object from a list.

ResourceFunction["LargestCellObject"][,n]

gives the n largest cells.

Details and Options

ResourceFunction["LargestCellObject"][nbo] accepts the same options as Cells.

Examples

Basic Examples (2) 

Create a notebook with content:

In[1]:=
nbo = CreateDocument[{TextCell["The head", "Section"],
   ExpressionCell[Framed@Pane["x", {200, 200}]],
   ExpressionCell[Iconize[Range[1000]]]}]
Out[1]=

Select the largest cell by ByteCount:

In[2]:=
big = ResourceFunction["LargestCellObject"][nbo]
Out[2]=
In[3]:=
SelectionMove[big, All, Cell]

Scope (3) 

Find the largest cell in this notebook:

In[4]:=
ResourceFunction["LargestCellObject"][]
Out[4]=

Find the ten largest cells in this notebook:

In[5]:=
ResourceFunction["LargestCellObject"][10]
Out[5]=

Find the 10 cells before this one in this notebook:

In[6]:=
cells = NestList[PreviousCell[#] &, EvaluationCell[], 10]
Out[6]=

Select the largest one from that list:

In[7]:=
big = ResourceFunction["LargestCellObject"][cells]
Out[7]=

Print the largest cell back out:

In[8]:=
CellPrint@NotebookRead[big]
Out[5]=

Options (4) 

Use the CellStyle option to limit the cells:

In[9]:=
nbo = CreateDocument[{TextCell["The head", "Section"],
   ExpressionCell[Framed@Pane["x", {200, 200}]],
   ExpressionCell[Range[10], "Input"],
   ExpressionCell[Range[11], "Input"],
   ExpressionCell[Range[10], "Output"]}]
Out[9]=

Find the largest input cell:

In[10]:=
ResourceFunction["LargestCellObject"][nbo, CellStyle -> "Input"]
Out[10]=

Find the two largest input cells:

In[11]:=
ResourceFunction["LargestCellObject"][nbo, 2, CellStyle -> "Input"]
Out[11]=

Find the largest output cell:

In[12]:=
ResourceFunction["LargestCellObject"][nbo, CellStyle -> "Output"]
Out[12]=

Properties and Relations (2) 

Omitting the count n gives the largest CellObject directly:

In[13]:=
ResourceFunction["LargestCellObject"][]
Out[13]=

Giving 1 as the count gives the largest cell in a list:

In[14]:=
ResourceFunction["LargestCellObject"][1]
Out[14]=

Applications (5) 

Retrieve a notebook:

In[15]:=
nbo = ResourceObject["Rhodobacter Capsulatus Whole Network"][
  "ExampleNotebook"]
Out[15]=

See the size:

In[16]:=
ByteCount[NotebookGet[nbo]]
Out[16]=

Find the three largest output cells:

In[17]:=
bigoutputs = ResourceFunction["LargestCellObject"][nbo, 3, CellStyle -> "Output"]
Out[17]=

Replace the outputs with images:

In[18]:=
NotebookWrite[#, Cell[BoxData[ToBoxes[Rasterize[#, RasterSize -> 300]]], "Output"]] & /@ bigoutputs
Out[18]=

The notebook is now much smaller:

In[19]:=
ByteCount[NotebookGet[nbo]]
Out[19]=
In[20]:=
NotebookClose[nbo]

Publisher

Bob

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 08 October 2025

Related Resources

License Information