NotebookImport[notebook,style]
imports cells with the given cell style from the specified notebook.
NotebookImport[notebook,styleform]
imports cells in the form specified by form.
NotebookImport
NotebookImport[notebook,style]
imports cells with the given cell style from the specified notebook.
NotebookImport[notebook,styleform]
imports cells in the form specified by form.
Details and Options
- In NotebookImport[notebook,…], notebook can be a NotebookObject, a file name, a CloudObject corresponding to a notebook, or a Notebook expression.
- If style is a pattern, cells whose style matches that pattern are imported. A typical pattern is "name1"|"name2"|…, indicating to import any of the styles namei.
- If style is _, all cells are imported.
- Possible values for form include:
-
"Boxes" first argument of low-level cell expression "Cell" complete low-level cell expression "Expression" cell converted to an expression "HeldExpression" cell converted to a held expression "HeldInterpretedCell" cell converted to a held TextCell or ExpressionCell "Hyperlinks" list of hyperlinks in the cell "InactiveExpression" cell converted to an inactive expression "InputText" cell contents as given by Copy As ▶ Input Text "InterpretedCell" cell converted to a TextCell or ExpressionCell "Text" cell contents as given by Copy As ▶ Plain Text - The following options can be given:
-
StripCellGrouping True whether to strip nested lists corresponding to the cell group hierarchy CellStyleImportRules Automatic specify forms to return for different cell styles - With the setting StripCellGroupingFalse, one level of the list will be present for every cell group in the notebook, whether or not any cells were imported from that group.
- The setting CellStyleImportRulesAutomatic is equivalent to the following mappings:
-
"Title" "Text" "Chapter" "Text" "Subchapter" "Text" "Section" "Text" "Subsection" "Text" "Subsubsection" "Text" "Text" "Text" "Code" "Cell" "Input" "HeldExpression" "Output" "Expression" "Message" "Text" "Print" "Print" - Other styles are given in "Boxes" form.
Examples
open all close allBasic Examples (1)
nb = CreateDocument[{TextCell["project title", "Title"], TextCell["first section", "Section"], TextCell["details", "Subsection"], ExpressionCell[Defer[2 + 2], "Input"], TextCell["second section", "Section"], ExpressionCell[Defer[3 + 3], "Input"], ExpressionCell[Defer[1 / 0], "Input"]}, WindowMargins -> {{Automatic, 0}, {Automatic, 0}}, WindowSize -> {500, 600}];
NotebookEvaluate[nb, InsertResults -> True];Import the cells in this notebook to the default forms:
NotebookImport[nb, _]Import cells in this notebook as a list of text strings:
NotebookImport[nb, _ -> "Text"]Import only Input-style cells, as held expressions:
NotebookImport[nb, "Input"]Import input cells as evaluatable text:
NotebookImport[nb, "Input" -> "InputText"]Import input cells as inactive expressions:
NotebookImport[nb, "Input" -> "InactiveExpression"]Import all input and output cells from a notebook, preserving cell grouping information:
NotebookImport[nb, "Input" | "Output", StripCellGrouping -> False]Import evaluatable text for every input and output cell:
NotebookImport[nb, "Input" | "Output" -> "InputText", StripCellGrouping -> False]Scope (6)
NotebookImport[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "document.nb"}], "Section" -> "Text"]Import from a Notebook expression:
NotebookImport[Notebook[{Cell[BoxData[RowBox[{"2", "+", "2"}]], "Input"]}], _ -> "InactiveExpression"]The "InterpretedCell" form results in a list of TextCell and ExpressionCell expressions, as appropriate:
NotebookImport[Notebook[{Cell[BoxData[RowBox[{"2", "+", "2"}]], "Input"]}], _ -> "InterpretedCell"]//InputFormThe "HeldInterpretedCell" form returns held expressions:
NotebookImport[Notebook[{Cell[BoxData[RowBox[{"2", "+", "2"}]], "Input"]}], _ -> "HeldInterpretedCell"]//InputFormThe "Cell" form returns expressions appropriate for use in low-level notebook operations, like NotebookPut:
NotebookPut @ Notebook @NotebookImport[EvaluationNotebook[], "ObjectName" | "Notes" -> "Cell"];The "Hyperlinks" form returns a list of Hyperlink expressions imported from each cell:
NotebookImport[EvaluationNotebook[], "Notes" -> "Hyperlinks"]Specify a custom importer to extract StyleBox structures from "Notes"-style cells:
NotebookImport[EvaluationNotebook[], "Notes" -> (Cases[#2, _StyleBox, Infinity]&)]Options (4)
CellStyleImportRules (2)
Specify different forms for different cell styles:
NotebookImport[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "document.nb"}], "Text" | "Input", CellStyleImportRules -> {"Text" -> "Text", "Input" -> "InputText"}]Different cell styles can specify different custom importers:
NotebookImport[EvaluationNotebook[], "Input" | "Output" | {"Message", "MSG"}, CellStyleImportRules -> {{"Message", "MSG"} -> (#2&), _ -> (#1 -> ByteCount[#2]&)}]StripCellGrouping (2)
Import a nested textual representation of some of the cells in a notebook:
NotebookImport[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "document.nb"}], "Subsection" | "Text" -> "Text", StripCellGrouping -> False]Import a nested textual representation of all the cells in a notebook:
NotebookImport[FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "document.nb"}], _ -> "Text", StripCellGrouping -> False]Possible Issues (2)
Cells that contain an incomplete expression will fail when imported to an expression-based form:
NotebookImport[Notebook[{Cell["2+", "Input"]}], "Input" -> "HeldExpression"]HoldComplete affects only evaluation, not typesetting:
NotebookImport[Notebook[{Cell["Grid[{{1,2},{3,4}}]", "Input"]}], "Input" -> "HeldExpression"]Use InputForm to see the untypeset form of the returned expressions:
InputForm[%]String-based forms are inert to evaluation and most typesetting:
NotebookImport[Notebook[{Cell["Grid[{{1,2},{3,4}}]", "Input"]}], "Input" -> "InputText"]Neat Examples (2)
Import historical information from a function's reference page:
docsDirectory = SystemInformation["FrontEnd", "DocumentationInformation"]["Directory"];StringTrim[NotebookImport[FileNameJoin[{docsDirectory, "English", "System", "ReferencePages", "Symbols", "NDSolve.nb"}], "HistorySection" -> "Text"]]Import the list of symbol names in the See Also links of a reference page:
docsDirectory = SystemInformation["FrontEnd", "DocumentationInformation"]["Directory"];
strings = StringTrim[NotebookImport[FileNameJoin[{docsDirectory, "English", "System", "ReferencePages", "Symbols", "NDSolve.nb"}], "SeeAlsoSection" -> "Text"]]StringSplit[strings, " ▪ " | "
"]Related Guides
Related Workflows
- Import Material from a Notebook ▪
- Import Tabular Data from a Notebook ▪
- Run a Notebook Programmatically
Text
Wolfram Research (2015), NotebookImport, Wolfram Language function, https://reference.wolfram.com/language/ref/NotebookImport.html (updated 2024).
CMS
Wolfram Language. 2015. "NotebookImport." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NotebookImport.html.
APA
Wolfram Language. (2015). NotebookImport. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NotebookImport.html
BibTeX
@misc{reference.wolfram_2026_notebookimport, author="Wolfram Research", title="{NotebookImport}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NotebookImport.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_notebookimport, organization={Wolfram Research}, title={NotebookImport}, year={2024}, url={https://reference.wolfram.com/language/ref/NotebookImport.html}, note=[Accessed: 13-June-2026]}