As of Version 14.1, NotebookCellData is a built-in symbol.

Function Repository Resource:

NotebookCellData

Source Notebook

Get structured data about a notebook's cells

Contributed by: Lou D'Andria

ResourceFunction["NotebookCellData"][]

returns data about the cells in the currently selected notebook.

ResourceFunction["NotebookCellData"][nbobj]

returns data about the cells in the given NotebookObject.

ResourceFunction["NotebookCellData"][{cellobj1,cellobj2,}]

returns data about each given CellObject.

ResourceFunction["NotebookCellData"][objs,elems]

includes the given elements of data.

ResourceFunction["NotebookCellData"][objs,elems,fmt]

returns data in the indicated format.

Details and Options

Supported elements include the name of any option to Cell, as a string or a symbol.
Elements can also include any key known to Developer`CellInformation, including "Style", "ContentData", "ContentDataForm", "FirstCellInGroup" and others.
Other supported elements include:
"CellByteCount"the ByteCount of the cell expression
"CellMemorySize"the size in memory for the cell
"CellContentMemorySize"the size in memory for the cell content
"CellImage"an image of the cell
"CellRasterSize"the raster size of the cell, in pixels
"CellThumbnail"a thumbnail of the cell
"CellGroupParent"the CellObject of the cell's group parent, if any
"CellGroupChildren"a list of the cell's group children, if any
"CellGroupDescendants"a list of the cell's group children at any depth, if any
"CellChangeCount"the number of change events stored for the cell
"FirstChangeTime"the earliest recorded change time for the cell
"LastChangeTime"the latest recorded change time for the cell
"CellContainsDynamics"whether the cell contains explicit dynamic boxes
"CellObject"the CellObject of the cell
"CellExpression"the Cell expression of the cell
"CellContents"the first argument of the Cell expression
"CellStyle"a list of the cell's styles
"CellOptions"the options of the Cell expression
When the "CellOptions" element is included, that will result in columns for any options which are directly set for any cell in the target objects.
The default for elems is Automatic, which includes "CellOptions", "CellMemorySize", "CellGroupParent" and "CellGroupChildren".
Supported formats include:
Automaticreturn the data as a List,Association, or Dataset, depending on elems
"Association"return the data as an Association
"Dataset"return the data as a Dataset
When elems is a string, default formatting will return a raw list of data.
Any other elems settings will return a Dataset by default.
Column headings will always be strings, even for elements specified as a symbol.
Keys are taken to be the corresponding CellObject expressions.
NotebookCellData supports the following Method options:
"KeyFunction"Identityfunction to apply to the CellObject when constructing keys
"NormalizeDates"Truewhether to return DateObject and DateInterval for values in CellChangeTimes

Examples

Basic Examples (7) 

Return data about cells in the current notebook:

In[1]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][]
Out[1]=

Return data for the first few cells:

In[2]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][Take[Cells[], 3]]
Out[2]=

Return specific elements of data:

In[3]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
 EvaluationNotebook[], {FontSize, "ContentDataForm", "CellContainsDynamics"}]
Out[3]=

When elems specifies a single element, NotebookCellData[objs,elems,] returns a raw list of data by default:

In[4]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][EvaluationNotebook[], FontSize]
Out[4]=

Return data as an Association:

In[5]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
 Take[Cells[], 3], {FontSize, "ContentDataForm", "CellContainsDynamics"}, "Association"]
Out[5]=

Get images for all "Section" cells in this notebook:

In[6]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][Cells[CellStyle -> "Section"], "CellImage"]
Out[6]=

Get data about the 5 cells in this notebook currently using the most memory:

In[7]:=
Take[ReverseSortBy[
  ResourceFunction[
   "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
   EvaluationNotebook[], {"CellMemorySize"}], #CellMemorySize &], UpTo[5]]
Out[7]=

Options (2) 

Method (2) 

In the data returned by NotebookCellData, each key is the CellObject of the corresponding cell:

In[8]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][Take[Cells[], 3], {FontSize}]
Out[8]=

Use the Method option "KeyFunction" to create a new key from the CellObject:

In[9]:=
ResourceFunction[
 "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][Take[Cells[], 3], {FontSize}, Method -> {"KeyFunction" -> First}]
Out[9]=

NotebookCellData returns DateObject and DateInterval objects for CellChangeTimes data:

In[10]:=
nbobj = CreateDocument[
   TextCell["This cell has been edited a few times.", "Text", CellChangeTimes -> {3.32361599873912*^9, 3.32613750470458*^9, {
      3.35031610729177*^9, 3.35031611397957*^9}}]];
ResourceFunction[
  "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][nbobj, CellChangeTimes] // First
Out[9]=

Use the Method option setting "NormalizeDates"False to obtain the raw data:

In[11]:=
ResourceFunction[
  "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][nbobj, CellChangeTimes, Method -> {"NormalizeDates" -> False}] // First
NotebookClose[nbobj];
Out[11]=

Applications (1) 

Visualize the editing times for a given notebook:

In[12]:=
nbobj = CreateDocument[{
Cell["1", "Text", CellChangeTimes -> {3.4444824423936205`*^9}], 
Cell["2", "Text", CellChangeTimes -> {{3.412516981482415*^9, 3.412516982048193*^9}}], 
Cell["3", "Text", CellChangeTimes -> {{3.427472909872077*^9, 3.427472914696743*^9}}], 
Cell["4", "Text", CellChangeTimes -> {{3.420217397361198*^9, 3.4202174044284153`*^9}}], 
Cell["5", "Text", CellChangeTimes -> {3.3872753382940884`*^9, 3.516060078927183*^9}], 
Cell["6", "Text", CellChangeTimes -> {3.3847982753800364`*^9, 3.5160600845101213`*^9}], 
Cell["7", "Text", CellChangeTimes -> {3.3847982195540447`*^9, 3.4202174314053164`*^9, 3.516060091967031*^9}], 
Cell["8", "Text", CellChangeTimes -> {{3.35761071493886*^9, 3.35761071659515*^9}, {
      3.35761080692559*^9, 3.35761094492912*^9}, {
      3.3793341868487034`*^9, 3.379334189286188*^9}, {
      3.4144285197902727`*^9, 3.414428538150117*^9}, {
      3.4193485464737043`*^9, 3.4193485498303757`*^9}}], 
Cell["9", "Text", CellChangeTimes -> {3.34539520742703*^9, {3.3798655051364307`*^9,
        3.379865528301485*^9}, 3.3847980833808603`*^9, 3.5160601106699953`*^9}], 
Cell["10", "Text", CellChangeTimes -> {{3.3740746557576714`*^9, 3.3740746960238123`*^9}, {3.374074727430464*^9, 3.3740747774154787`*^9}, 3.384798111235463*^9, 3.516060115277295*^9}], 
Cell["11", "Text", CellChangeTimes -> {{3.36891576154688*^9, 3.36891578507813*^9}, {
      3.3689158221875*^9, 3.36891582357813*^9}, {3.3689230085*^9, 3.36892301185938*^9}}], 
Cell["12", "Text", CellChangeTimes -> {{3.36891583429688*^9, 3.36891585385938*^9}, {
      3.36892301671875*^9, 3.368923020125*^9}}], 
Cell["13", "Text", CellChangeTimes -> {{3.36613363257713*^9, 3.36613363693659*^9}, {
      3.37045263668003*^9, 3.370452637552829*^9}, {
      3.395792940734375*^9, 3.395792943171875*^9}}], 
Cell["14", "Text", CellChangeTimes -> {{3.35438590275429*^9, 3.35438592495798*^9}, {
      3.379864787199745*^9, 3.379864806200323*^9}}], 
Cell["15", "Text", CellChangeTimes -> {3.3798648015928183`*^9}], 
Cell["16", "Text", CellChangeTimes -> {3.372003186046875*^9, 3.380475050356851*^9}], 
Cell["17", "Text", CellChangeTimes -> {{3.35438594664604*^9, 3.35438596153705*^9}, {
      3.379864792225019*^9, 3.3798648136168137`*^9}}], 
Cell["18", "Text", CellChangeTimes -> {{3.35438573474999*^9, 3.35438576856336*^9}, {
      3.35438580945503*^9, 3.35438584904979*^9}, {3.35438597181856*^9,
       3.35438597505302*^9}}], 
Cell["19", "Text", CellChangeTimes -> {3.3719078611409597`*^9, 3.3804750648559227`*^9}], 
Cell["20", "Text", CellChangeTimes -> {{3.36603019384561*^9, 3.36603020278374*^9}, {
      3.3798644024142036`*^9, 3.379864403025096*^9}, {
      3.384798096318224*^9, 3.3847980970191107`*^9}}], 
Cell["21", "Text", CellChangeTimes -> {{3.36603010399553*^9, 3.36603018840772*^9}, {
      3.3725127111013546`*^9, 3.3725127201169796`*^9}}], 
Cell["22", "Text", CellChangeTimes -> {3.3725137836013546`*^9, 3.3804750794484625`*^9, 3.381072336410405*^9}], 
Cell["23", "Text", CellChangeTimes -> {{3.35769102076656*^9, 3.35769102440723*^9}, {
      3.3776208310109005`*^9, 3.3776208326829042`*^9}, {
      3.3798589092538433`*^9, 3.3798589100446787`*^9}}], 
Cell["24", "Text", CellChangeTimes -> {{3.3719079385159597`*^9, 3.3719079509378347`*^9}, {3.372002890484375*^9, 3.372002893125*^9}, {3.372002939609375*^9, 3.372002940078125*^9}}], 
Cell["25", "Text", CellChangeTimes -> {{3.372002951578125*^9, 3.372002959453125*^9}, {3.3725129462107296`*^9, 3.3725129483982296`*^9}}], 
Cell["26", "Text", CellChangeTimes -> {3.3720029599375*^9, {3.372010845010665*^9, 3.372010855808231*^9}, 3.3725129487263546`*^9, 3.3876293923932734`*^9}], 
Cell["27", "Text", CellChangeTimes -> {{3.3720029281875*^9, 3.3720029341875*^9}}], 
Cell["28", "Text", CellChangeTimes -> {{3.3719081004690847`*^9, 3.3719081671878347`*^9}, {3.372002895328125*^9, 3.372002912296875*^9}, 3.3795366089456673`*^9, {
       3.3797027268849373`*^9, 3.379702731119664*^9}}], 
Cell["29", "Text", CellChangeTimes -> {{3.3719079797034597`*^9, 3.3719080435628347`*^9}, {3.3719080882503347`*^9, 3.3719080995472097`*^9}, {3.3719081703284597`*^9, 3.3719081710472097`*^9}, {3.372002916234375*^9, 3.372002920421875*^9}, {3.3725129268357296`*^9, 3.3725129412732296`*^9}, {3.379702709383481*^9, 3.3797027095084915`*^9}, {3.379702760887766*^9, 3.379702773091906*^9}}], 
Cell["30", "Text", CellChangeTimes -> {{3.3719079617034597`*^9, 3.3719080441565847`*^9}, {3.3719080910003347`*^9, 3.3719080938440847`*^9}, 3.3719081713284597`*^9, 3.37200292090625*^9, {3.372010869309095*^9, 3.3720108769189568`*^9}, {3.3725129294138546`*^9, 3.3725129517576046`*^9}, {3.3795366104827147`*^9, 3.3795366183234158`*^9}, {3.37970271027418*^9, 3.379702773654453*^9}}], 
Cell["31", "Text", CellChangeTimes -> {{3.379864089239335*^9, 3.379864100416102*^9}, {3.379864242857267*^9, 3.3798642445111*^9}, {3.3872753316533356`*^9, 3.3872753319814672`*^9}}], 
Cell["32", "Text", CellChangeTimes -> {3.380474796716835*^9, 3.380474846885499*^9}], 
Cell["33", "Text", CellChangeTimes -> {3.384798072429367*^9, 3.420217524782189*^9}], 
Cell["34", "Text", CellChangeTimes -> {3.3804748141844673`*^9}], 
Cell["35", "Text", CellChangeTimes -> {{3.35769102076656*^9, 3.35769102440723*^9}, {
      3.3776208310109005`*^9, 3.3776208326829042`*^9}, {
      3.3798589092538433`*^9, 3.379858927748384*^9}, {
      3.379862880965726*^9, 3.379862880965797*^9}}], 
Cell["36", "Text", CellChangeTimes -> {{3.35438635721905*^9, 3.35438637796958*^9}, {
       3.372003155984375*^9, 3.372003156375*^9}, {
       3.379863698031989*^9, 3.379863704634852*^9}, 3.379863743204739*^9, {3.380474918537163*^9, 3.3804749582533712`*^9}, {3.387277349051444*^9, 3.387277349426451*^9}}], 
Cell["37", "Text", CellChangeTimes -> {{3.35438600621006*^9, 3.35438615890147*^9}, {
      3.3543862107153*^9, 3.35438630768653*^9}, {3.35438642133007*^9, 3.35438646625309*^9}, {3.3720030413125*^9, 3.372003111453125*^9}}], 
Cell["38", "Text", CellChangeTimes -> {3.3725136688357296`*^9}], 
Cell["39", "Text", CellChangeTimes -> {{3.3725136127888546`*^9, 3.3725136335232296`*^9}}], 
Cell["40", "Text", CellChangeTimes -> {{3.379702628486126*^9, 3.3797026391901417`*^9}, {3.379858989460732*^9, 3.3798589936253138`*^9}}], 
Cell["41", "Text", CellChangeTimes -> {3.379858993999892*^9, 3.380474970736947*^9}], 
Cell["42", "Text", CellChangeTimes -> {{3.3804749953916187`*^9, 3.3804749984695473`*^9}}], 
Cell["43", "Text", CellChangeTimes -> {{3.3725130277263546`*^9, 3.3725130512419796`*^9}}], 
Cell["44", "Text", CellChangeTimes -> {3.379700292541792*^9, 3.380472810683*^9}], 
Cell["45", "Text", CellChangeTimes -> {3.5160601656063347`*^9}], 
Cell["46", "Text", CellChangeTimes -> {3.380472846042375*^9}], 
Cell["47", "Text", CellChangeTimes -> {{3.385310623617546*^9, 3.3853106368976917`*^9}}], 
Cell["48", "Text", CellChangeTimes -> {3.38047285190175*^9}], 
Cell["49", "Text", CellChangeTimes -> {3.38047286877675*^9}], 
Cell["50", "Text", CellChangeTimes -> {{3.3797004812762427`*^9, 3.3797004938866673`*^9}, {3.3797005534853754`*^9, 3.3797005549229946`*^9}}], 
Cell["51", "Text", CellChangeTimes -> {3.37970044644522*^9, 3.379700494730487*^9, 3.3797005554699154`*^9, 3.380472868886125*^9}], 
Cell["52", "Text", CellChangeTimes -> {3.516060184965111*^9}], 
Cell["53", "Text", CellChangeTimes -> {3.3797000880247774`*^9, 3.3804728813705*^9}], 
Cell["54", "Text", CellChangeTimes -> {{3.3847981750149603`*^9, 3.384798181162547*^9}, {3.3853106563804455`*^9, 3.385310657505373*^9}}], 
Cell["55", "Text", CellChangeTimes -> {3.379700089149871*^9, 3.380472881479875*^9}], 
Cell["56", "Text", CellChangeTimes -> {3.380472891308*^9}], 
Cell["57", "Text", CellChangeTimes -> {3.3804741228918395`*^9}], 
Cell["58", "Text", CellChangeTimes -> {3.3847982261671257`*^9}], 
Cell["59", "Text", CellChangeTimes -> {3.380474176986923*^9}], 
Cell["60", "Text", CellChangeTimes -> {3.380474212998213*^9}], 
Cell["61", "Text", CellChangeTimes -> {{3.384091792082692*^9, 3.384091912035812*^9}, {3.384091985201563*^9, 3.384092025175125*^9}, 3.5160601992749357`*^9}], 
Cell["62", "Text", CellChangeTimes -> {{3.3840913160811243`*^9, 3.384091460665957*^9}, 3.38409197645783*^9, {
       3.384092032549017*^9, 3.3840920334122334`*^9}}], 
Cell["63", "Text", CellChangeTimes -> {3.3840920368255053`*^9}], 
Cell["64", "Text", CellChangeTimes -> {{3.3840920457235622`*^9, 3.384092048751995*^9}, {3.38409207959451*^9, 3.384092112887143*^9}, {3.3853106670985703`*^9, 3.385310675363719*^9}}], 
Cell["65", "Text", CellChangeTimes -> {{3.384092056263586*^9, 3.384092061156354*^9}}], 
Cell["66", "Text", CellChangeTimes -> {3.3840920615627537`*^9}], 
Cell["67", "Text", CellChangeTimes -> {{3.3797008144914637`*^9, 3.379700825086096*^9}}], 
Cell["68", "Text", CellChangeTimes -> {3.379700825382995*^9}], 
Cell["69", "Text", CellChangeTimes -> {{3.379703358296841*^9, 3.3797033796267405`*^9}, {3.3797034367096148`*^9, 3.379703450695153*^9}, {3.37970348377603*^9, 3.3797034862918644`*^9}, {3.379703532655096*^9, 3.379703562110672*^9}, {3.3797036458988924`*^9, 3.379703647992817*^9}}], 
Cell["70", "Text", CellChangeTimes -> {3.3797036683538857`*^9}], 
Cell["71", "Text", CellChangeTimes -> {{3.379700758236784*^9, 3.3797007861297293`*^9}, {3.3798637544365597`*^9, 3.379863754989675*^9}, 3.384798282322075*^9}], 
Cell["72", "Text", CellChangeTimes -> {{3.3804742374590063`*^9, 3.380474238256131*^9}}], 
Cell["73", "Text", CellChangeTimes -> {3.379700753064479*^9, 3.3804742404130573`*^9}], 
Cell["74", "Text", CellChangeTimes -> {{3.3804746439212093`*^9, 3.380474678374555*^9}, {3.3804747183435607`*^9, 3.3804747531250334`*^9}}], 
Cell["75", "Text", CellChangeTimes -> {3.380474708999751*^9}], 
Cell["76", "Text", CellChangeTimes -> {3.3797009312824306`*^9, 3.380474297493452*^9}], 
Cell["77", "Text", CellChangeTimes -> {3.34539501489416*^9, {3.37200393559375*^9, 3.372003936265625*^9}, 3.3720110178498507`*^9}], 
Cell["78", "Text", CellChangeTimes -> {3.34539499192335*^9, {3.372003790859375*^9, 3.372003803796875*^9}, {3.3725124623044796`*^9, 3.3725125344294796`*^9}, {3.3725125709607296`*^9, 3.3725126149763546`*^9}, {3.3725138402576046`*^9, 3.3725139139763546`*^9}, {3.3725143756013546`*^9, 3.3725143778044796`*^9}, 3.379700892404196*^9}], 
Cell["79", "Text", CellChangeTimes -> {3.3797009084367795`*^9, 3.3804742973371534`*^9}], 
Cell["80", "Text", CellChangeTimes -> {{3.35438629649875*^9, 3.35438630218639*^9}}], 
Cell["81", "Text", CellChangeTimes -> {{3.35438600621006*^9, 3.35438615890147*^9}, {
      3.3543862107153*^9, 3.35438630768653*^9}, {3.35438642133007*^9, 3.35438644864327*^9}}], 
Cell["82", "Text", CellChangeTimes -> {{3.35438614493237*^9, 3.35438631901495*^9}, {
       3.35438644937766*^9, 3.35438645404965*^9}, 3.3719078890472097`*^9, 3.3720110767754965`*^9, 3.3795347306200027`*^9}], 
Cell["83", "Text", CellChangeTimes -> {{3.3853107284387865`*^9, 3.385310734344697*^9}}], 
Cell["84", "Text", CellChangeTimes -> {{3.3797010330877748`*^9, 3.3797010334784327`*^9}, {3.37970106837196*^9, 3.3797010707002788`*^9}, {3.379701175162094*^9, 3.3797013456919065`*^9}, {3.379701382288701*^9, 3.3797014215888453`*^9}, {3.3797014544040756`*^9, 3.37970148589107*^9}, {3.3797015537092123`*^9, 3.3797015591159115`*^9}, {3.3797016269028015`*^9, 3.3797016412008657`*^9}, {3.3797025077729588`*^9, 3.3797025080854845`*^9}}], 
Cell["85", "Text", CellChangeTimes -> {3.3797012906091986`*^9, {
       3.3797013319407625`*^9, 3.379701347035768*^9}, {
       3.379701402634144*^9, 3.3797014867505164`*^9}, 3.379701560662915*^9, 3.3797016459512606`*^9, 3.3797025088824253`*^9}], 
Cell["86", "Text", CellChangeTimes -> {{3.379702437220214*^9, 3.3797024551279535`*^9}, {3.379702537884838*^9, 3.379702549635816*^9}}], 
Cell["87", "Text", CellChangeTimes -> {{3.3797017261454325`*^9, 3.3797017569761224`*^9}, {3.379701907113613*^9, 3.3797019151142783`*^9}, {3.379701952664277*^9, 3.3797020421873503`*^9}, {3.3797020804874115`*^9, 3.3797021679009333`*^9}, {3.379702203794544*^9, 3.379702284988799*^9}, 3.379980662033142*^9, {
       3.3955779435022974`*^9, 3.3955779471584773`*^9}}], 
Cell["88", "Text", CellChangeTimes -> {{3.3797020074344587`*^9, 3.3797020428905334`*^9}, 3.379702102348605*^9, 3.3797021699010997`*^9, 3.3797022558770027`*^9, 3.379980664080056*^9, 3.3955779504396644`*^9, 3.3955779820484324`*^9}]}];
TimelinePlot[
 ResourceFunction[
   "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][nbobj, CellChangeTimes] // Reverse]
Out[9]=
In[13]:=
DateHistogram[
 ResourceFunction[
  "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][nbobj, CellChangeTimes]]
Out[13]=
In[14]:=
NotebookClose[nbobj];

Neat Examples (1) 

Create a collage of images of this notebook's cells, where cells with a larger byte count appear larger:

In[15]:=
ds = ResourceFunction[
   "NotebookCellData", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
   EvaluationNotebook[], {"CellByteCount", "CellImage"}];
In[16]:=
ImageCollage[
 Normal[ds[Values, #CellByteCount -> #CellImage &]], Sequence[
 Background -> White, ImagePadding -> 1, Padding -> Gray]]
Out[16]=

Publisher

Lou D'Andria

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.1 – 11 August 2023
  • 1.0.0 – 25 May 2023

License Information