# Create, Open and Save Workbooks

You can create workbooks from scratch, open existing files as workbooks, and save workbooks into different file formats. The following sections describe these operations.

* [Create a Workbook](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/working-with-workbooks/create-open-and-save-workbooks#create-a-workbook)

* [Open a Workbook](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/working-with-workbooks/create-open-and-save-workbooks#open-a-workbook)

* [Save a Workbook](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/working-with-workbooks/create-open-and-save-workbooks#save-a-workbook)

## Create a Workbook

The fact that RadSpreadProcessing is completely decoupled from UI enables numerous server side scenarios that build a document from scratch. The model allows you to create a new workbook using the nullary constructor of the `Workbook` class. When a new workbook is created in this manner, its `Worksheets` collection is still empty.

**Example 1** creates a new workbook and adds its first worksheet, which also becomes the `ActiveWorksheet` of the workbook.

**Example 1: Create a workbook and add its first worksheet**

```C#
Telerik.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Documents.Spreadsheet.Model.Workbook();
Telerik.Documents.Spreadsheet.Model.Worksheet worksheet = workbook.Worksheets.Add();
```

## Open a Workbook

RadSpreadProcessing allows you to import a workbook from a number of formats. The model supports `csv`, `txt`, `xlsx`, `xls` file formats, and `DataTable` objects.

To import a workbook, instantiate a specific [FormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/general-information), invoke its `Import()` method, and pass a `Stream` or `byte[]` array as an argument.

**Example 2** uses a `WebClient` to download a `xlsx` file stored on a server. The code then creates a [XlsxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider) object and invokes its `public Workbook Import(Stream stream)` method.

**Example 2: Download an XLSX file with WebClient and import it through XlsxFormatProvider**

```C#
const string FilePath = @"http://localhost:54352/Resourses/SampleFile.xlsx";
WebClient webClient = new WebClient();

webClient.OpenReadCompleted += (sender, eventArgs) =>
{
	Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
	Telerik.Documents.Spreadsheet.Model.Workbook workbook = formatProvider.Import(eventArgs.Result, TimeSpan.FromSeconds(10));
};

webClient.OpenReadAsync(new Uri(FilePath));
```

> note Additional examples about import are available in the [Import/Load and Export/Save RadSpreadProcessing Workbook](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/import-export-save-load-workbook) knowledge base article.

## Save a Workbook

RadSpreadProcessing also allows you to save a workbook into a `XLSX`, `XLS`, `CSV`, `TXT`, and `PDF` file format as well as into a `DataTable` object.

To export a workbook, instantiate the [FormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/general-information) you want to use and invoke its `Export()` method.

**Example 3** demonstrates how to export an existing `Workbook` to a `XLSX` file. The snippet creates a new workbook with a single worksheet. It then creates a [XlsxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider) object and invokes its `public void Export(Workbook workbook, Stream output)` method. Saving to the other formats works the same way with a different format provider class.

**Example 3: Create a workbook and export it to an XLSX file stream**

```C#
Workbook workbook = new Workbook();
workbook.Worksheets.Add();

string fileName = "SampleFile.xlsx";
XlsxFormatProvider formatProvider = new XlsxFormatProvider();

using (Stream output = new FileStream(fileName, FileMode.Create))
{
	formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
}
```

**Example 4** passes the stream returned by the dialog and the current workbook to the `Export()` method of the [CsvFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/csv/csvformatprovider).

**Example 4: Export a workbook to CSV by using a SaveFileDialog stream**

```C#
Workbook workbook = new Workbook();
workbook.Worksheets.Add();

SaveFileDialog saveFileDialog = new SaveFileDialog();
CsvFormatProvider formatProvider = new CsvFormatProvider();
saveFileDialog.Filter = "CSV (comma delimited) (*.csv)|*.csv|All Files (*.*)|*.*";

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
	using (Stream output = saveFileDialog.OpenFile())
	{
		formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
	}
}
```

> note Additional examples about export are available in the [Import/Load and Export/Save RadSpreadProcessing Workbook](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/import-export-save-load-workbook) knowledge base article.

## See Also

* [Formats and Conversion](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/general-information)
* [Import/Load and Export/Save RadSpreadProcessing Workbook KB](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/import-export-save-load-workbook)
