NotebookWrite
Writes content to a notebook or replaces the content of a specific cell.
Syntax
Writing to a notebook:
NotebookWrite[notebook_RemoteNotebook, expr_]
NotebookWrite[notebook_RemoteNotebook, {expr1_, expr2_, ...}]Writing to a cell:
NotebookWrite[cell_RemoteCellObj, expr_String]
NotebookWrite[cell_RemoteCellObj, expr_]Basic Usage
See also CreateWindow and CellPrint
Appending to a Notebook
Writing to a notebook appends new cells, similar to CellPrint:
NotebookWrite[EvaluationNotebook[], Plot[x, {x, 0, 1}]];Overwriting a Cell
Writing to a RemoteCellObj replaces the content of that cell:
NotebookWrite[NotebookFocusedCell[], Plot[x, {x, 0, 1}]];Only input cells can be overwritten.
Controlling Insertion Location
Use NotebookLocationSpecifier to control exactly where content is written:
Insert after a specific cell:
NotebookWrite[NotebookLocationSpecifier[cell, "After"], expr]Overwrite a specific cell:
NotebookWrite[NotebookLocationSpecifier[cell, "On"], expr]Writting to NotebookStore
Use NotebookStore to write the raw data into local notebook storage:
NotebookWrite[NotebookStore["key"], Now];Cell Types
Using Cell, ExpressionCell or TextCell wrapper you can specify the properties of inserted cell:
NotebookWrite[EvaluationNotebook[], cell]where cell can be
Cell[expr_String, "Input"]Cell[expr_String, "Output"]Cell[expr_String, "Input"]Cell[expr_String, "Output", subtype_String]TextCell[expr_String]TextCell[expr_String, "Title"]TextCell[expr_String, "Section"]TextCell[expr_String, "Subsection"]ExpressionCell[expr_, "Input"]ExpressionCell[expr_, "Output"]
subtype property can be any view-component provided by known cell types:
"WLX"or"wlx""HTML"or"html""JS"or"js"or"javascript""MERMAID"or"mermaid"- ...
For example to create an output HTML cell:
NotebookWrite[EvaluationNotebook[], Cell["<h1>Hello World</h1>", "Output", "HTML"]]