({{, (RefLink[NotebookRead, paclet:ref/NotebookRead])[notebook]
gives the expression corresponding to the current selection in the specified notebook object. }, {, (RefLink[NotebookRead, paclet:ref/NotebookRead])[obj]
gives the expression corresponding to the given cell or box object.}, {, (RefLink[NotebookRead, paclet:ref/NotebookRead])[{(Subscript[obj, 1]),(Subscript[obj, 2]),…}]
gives a list of expressions corresponding to the (Subscript[obj, i]).}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[NotebookRead, paclet:ref/NotebookRead]) is the basic way to get into the kernel pieces of notebooks that are being manipulated by the front end.

(RefLink[NotebookRead, paclet:ref/NotebookRead]) can take a (RefLink[NotebookObject, paclet:ref/NotebookObject]), (RefLink[CellObject, paclet:ref/CellObject]), or (RefLink[BoxObject, paclet:ref/BoxObject]).

If a list of (RefLink[CellObject, paclet:ref/CellObject]) or (RefLink[BoxObject, paclet:ref/BoxObject]) expressions is given, then a list of equal length will be returned, with the expressions corresponding to each object.

If an object is no longer valid, (RefLink[NotebookRead, paclet:ref/NotebookRead]) returns (RefLink[$Failed, paclet:ref/$Failed]). If a list of objects is given, then (RefLink[$Failed, paclet:ref/$Failed]) will be returned for each of the invalid objects.

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

This creates a document notebook:

nb=CreateDocument[{"This is the quadratic formula:",(-b±Sqrt[b^2-4 a c])/(2 a)//TraditionalForm}]

This selects the first cell:

SelectionMove[nb,Next,Cell]

This reads the cell and returns its (RefLink[Cell, paclet:ref/Cell]) expression:

NotebookRead[nb]

Read a (RefLink[CellObject, paclet:ref/CellObject]):

NotebookRead[EvaluationCell[]]

Read a (RefLink[BoxObject, paclet:ref/BoxObject]):

Button["click",Print[NotebookRead[EvaluationBox[]]]]

OpenersExampleSection1(Spacer1)Scope  (1)

Create a notebook and move the selection to the first "T":

nb=CreateWindow[DocumentNotebook[{CellGroup[{TextCell["Text Group","Section"],TextCell["Mary had a little lamb.","Text"],TextCell["Its fleece was white as snow.","Text"]}],CellGroup[{TextCell["Graphics Group","Section"],ExpressionCell[ Plot[Exp[-x^2],{x,-3,3}],"Output"]}]}]];

SelectionMove[nb,Before,CellContents];
SelectionMove[nb,All,Character]

Read the current selection:

NotebookRead[nb]

Select multiple cells and read the content:

SelectionMove[nb,All,CellGroup]

NotebookRead[nb]

Select and read graphics:

SelectionMove[nb,Next,CellContents,2]

grbox=NotebookRead[nb];

Display the result:

ToExpression[grbox]

OpenersExampleSection2(Spacer1)Applications  (1)

A palette that reads the word at the current selection and makes it uppercase:

PaletteNotebook[Button["Make Upper Case",
With[{in=InputNotebook[]},SelectionMove[in,All,Word];NotebookWrite[in,ToUpperCase[NotebookRead[in]]]]]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NotebookGet, paclet:ref/NotebookGet])  ▪  (RefLink[NotebookImport, paclet:ref/NotebookImport])  ▪  (RefLink[NotebookWrite, paclet:ref/NotebookWrite])  ▪  (RefLink[NotebookDelete, paclet:ref/NotebookDelete])  ▪  (RefLink[ButtonSource, paclet:ref/ButtonSource])  ▪  (RefLink[CopyToClipboard, paclet:ref/CopyToClipboard])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Notebooks from the Kernel, paclet:tutorial/ManipulatingNotebooksFromTheKernel])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Low-Level Notebook Programming, paclet:guide/LowLevelNotebookProgramming])}, {▪(RefLinkPlain[Notebook Document Generation, paclet:guide/DocumentGeneration])}})}})