Export Cells

Introduction

The Export Cells palette enables you to extract content of a specified type from a given notebook or project and save the content in a desired format. For example, you can extract all the graphics cells from a notebook and save each graphic as a separate GIF file.

1.gif

You can extract content of the following types:

Exporting Cells

To export all cells of a specified style:

1.  For a single notebook, open it and make it the currently selected notebook. For multiple notebooks, open the Make Project dialog box and load the project file for your project. (If you have not already created a project file, see "Creating a Project File" to learn how.)

2.  Open the Export Cells palette.

3.  Click Cells of Style.

4.  In the dialog box that appears, enter the style of the cells you want to export.

5.  Click OK to close the dialog box and apply the changes to your notebook. Click Cancel if you do not want the changes to be saved. Click Apply to apply the changes without closing the dialog box. Then click OK.

The cells you specified are extracted from the source notebook(s) and saved in the same directory. By default, the exported cells are saved in a new notebook. If you want to export cells in a different format, you must set the value of the option ExportFormat as explained in "Specifying the Export Format".

To export all cell groups of a specified style:

1.  For a single notebook, open the notebook and make it the currently selected notebook. For multiple notebooks, open the Make Project dialog box and load the project file for your project. (If you have not already created a project file, see "Creating a Project File" to learn how.)

2.  Open the Export Cells palette.

3.  Click Cell Groups of Style.

4.  In the dialog box that appears, enter the style of the heading cells for the cell groups you want to export. Then click OK.

The cells you specified are extracted from the source notebook(s) and saved in the same directory. By default the exported cells are saved in a new notebook. If you want to export cells in a different format, you must set the value of the option ExportFormat, as explained in "Specifying the Export Format".

To export all cells with a specified cell tag:

1.  For a single notebook, open the notebook and make it the currently selected notebook. For multiple notebooks, open the Make Project dialog box and load the project file for your project. (If you have not already created a project file, see "Creating a Project File" to learn how.)

2.  Open the Export Cells palette.

3.  Click Cells with CellTag.

4.  In the dialog box that appears, enter the cell tag of the cells you want to export. Then click OK.

All cells with the cell tag you specified are extracted from the source notebook(s) and saved in the same directory. By default, the exported cells are saved in a new notebook. If you want to export cells in a different format, you must set the value of the option ExportFormat as explained in "Specifying the Export Format".

Specifying the Export Format

To specify the export format:

1.  Click ExportFormat. This brings up a dialog box showing the current setting of the ExportFormat option.

2.  Specify the format you want to save in by typing it into the text box. You can also click a button bearing the name of a specific format to paste that format into the text box.

3.  Click Apply for the new setting to take effect. Click OK or Close to close the dialog box.

Specifying the Export Directory

To specify the directory to export to:

1.  Click Export To Directory. This brings up a dialog box showing the current setting of the ExportDirectory option.

2.  In the text box, enter the full pathname of the directory you want to save to. You can also use the Browse button to bring up a file dialog box, then locate a file in the target directory and click Open.

3.  Click Apply for the option to take effect. Click OK to close the dialog box.

Specifying the Extraction Method

To specify the extraction method:

1.  Click ExtractionMethod. This brings up a dialog box showing the current setting of the ExtractionMethod option.

2.  Enter the extraction method you want to use in the text box. Possible settings are:

3.  Click Apply for the new setting to take effect. Click OK or Close to close the dialog box.

Extracting Cells from a Notebook Programmatically

The Wolfram System kernel refers to any open notebook via an expression of the form NotebookObject[fe,id], where fe specifies the front end in which the notebook is open and id is a unique serial number for the notebook.

The command Notebooks[] returns a list of notebook objects corresponding to all notebooks currently open in the front end.

This assigns the variable nb to represent the first notebook object in the list.

Alternatively, you can identify a notebook by specifying the name and location of the notebook file. You can use the ToFileName function to construct a string specifying the full pathname of the file.

This loads the AuthorTools package.

This exports all cells of Section style to a notebook.

You can also extract all Section cells by specifying a list of two elements as the second argument. ExportNotebook[nb,{"CellStyle","Section"},"Notebook"] is equivalent to ExportNotebook[nb,"Section", "Notebook"].

This command exports all cell groups in which the heading cell is an Input cell. This enables you, for example, to extract all input-output pairs in a notebook.

This command exports all cells having the cell tag "Reference1".

This command exports all graphics cells as separate GIF files.