({{, (RefLink[NotebookWrite, paclet:ref/NotebookWrite])[notebook,data]
writes data into a notebook at the current selection, setting the current selection to be just after the data written. }, {, (RefLink[NotebookWrite, paclet:ref/NotebookWrite])[obj,data]
replaces the given cell or box object instead of the current selection.}, {, (RefLink[NotebookWrite, paclet:ref/NotebookWrite])[obj,data,sel]
writes data into a notebook, setting the current selection to be as specified by sel. }})

OpenersNotesSection(Spacer1)Details and Options

The first argument of (RefLink[NotebookWrite, paclet:ref/NotebookWrite]) can be a (RefLink[NotebookObject, paclet:ref/NotebookObject]), (RefLink[CellObject, paclet:ref/CellObject]), or (RefLink[BoxObject, paclet:ref/BoxObject]).

(RefLink[NotebookWrite, paclet:ref/NotebookWrite]) to a (RefLink[NotebookObject, paclet:ref/NotebookObject]) does essentially the same as a Paste operation in the front end: it replaces whatever the current selection in the notebook is by data.

(RefLink[NotebookWrite, paclet:ref/NotebookWrite]) to a (RefLink[CellObject, paclet:ref/CellObject]) replaces the given cell with the specified content. If no third argument is specified and the selection is not inside the cell, it does this without disturbing the current selection.

(RefLink[NotebookWrite, paclet:ref/NotebookWrite]) is the basic way to use the Wolfram Language kernel to modify the contents of notebooks that are being manipulated by the front end.

(RefLink[NotebookWrite, paclet:ref/NotebookWrite]) automatically wraps (RefLink[Cell, paclet:ref/Cell]) around the data you specify if this is necessary.

Possible settings for sel are:

The default for sel is (RefLink[After, paclet:ref/After]), so that (RefLink[NotebookWrite, paclet:ref/NotebookWrite])[obj,data] can be called repeatedly to insert several pieces of data in sequence.

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Create an empty notebook and write a cell:

nb=CreateDocument[];

NotebookWrite[nb,Cell["New content","Subsection"]]

Write another cell and select it:

NotebookWrite[nb,Cell["Next cell","Subsection"],All]

OpenersExampleSection1(Spacer1)Scope  (2)

Overwrite an existing cell:

Dynamic[cell=EvaluationCell[]]

NotebookWrite[cell,Cell["output cell","Output"],All]

Display a button that replaces itself when clicked:

Button["click",NotebookWrite[EvaluationBox[],ToBoxes[DateString[]]]]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)AutoScroll  (1)

First create an empty sample notebook to operate on:

nb=CreateDocument[];

Write a tall cell expression to the sample notebook and the scroll position remains at the top:

NotebookWrite[nb,Cell[BoxData[ToBoxes[Column[Table[x,{x,1,200}]]]]],AutoScroll->False]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

nb=CreateDocument[{TextCell["First.", "Text"],TextCell["Second.","Text"]}];

Use (RefLink[NotebookWrite, paclet:ref/NotebookWrite]) to write over a selected part of the document:

SelectionMove[nb,Next,Cell];
NotebookWrite[nb,Cell["New first.","Text"]]

Or use (RefLink[NotebookPut, paclet:ref/NotebookPut]) to replace the full contents:

NotebookPut[Notebook[{Cell["Completely new","Text"]}],nb];

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NotebookApply, paclet:ref/NotebookApply])  ▪  (RefLink[Paste, paclet:ref/Paste])  ▪  (RefLink[NotebookRead, paclet:ref/NotebookRead])  ▪  (RefLink[NotebookDelete, paclet:ref/NotebookDelete])  ▪  (RefLink[SelectionMove, paclet:ref/SelectionMove])}})}})

({{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[Clipboard Operations, paclet:guide/ClipboardOperations])}, {▪(RefLinkPlain[Notebook Document Generation, paclet:guide/DocumentGeneration])}, {▪(RefLinkPlain[Low-Level Interface Control, paclet:guide/LowLevelInterfaceControl])}})}})