# Using CsvFormatProvider

`CsvFormatProvider` makes it easy to import and export CSV files. CSV is a plain text format, meaning that it keeps only the contents of the worksheet without its formatting. Exporting a file to CSV strips all styling and saves only the cell result value with the respective format applied. The provider exports only the contents of the active worksheet. Exporting multiple worksheets into a single CSV file is not supported.

To import and export CSV files, use the `CsvFormatProvider` class that appears in the `Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Csv` namespace. The `CsvFormatProvider` implements the `IWorkbookFormatProvider` interface which is contained in the `Telerik.Windows.Documents.Spreadsheet.FormatProviders` namespace.

> note For more examples and application scenarios of importing and exporting a Workbook to various formats using a FormatProvider, check out 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.

## Import

**Example 1** shows how to import a CSV file using a `FileStream`. The code assures that a file with the specified name exists. Further, the sample instantiates a `CsvFormatProvider` and passes a `FileStream` to its `Import()` method.

**Example 1: Import CSV File**

```C#
string fileName = "FileName.csv";
if (!File.Exists(fileName))
{
    throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
}

Workbook workbook;
CsvFormatProvider formatProvider = new CsvFormatProvider();

using (Stream input = new FileStream(fileName, FileMode.Open))
{
    workbook = formatProvider.Import(input, TimeSpan.FromSeconds(10));
}
```

## Export

**Example 2** demonstrates how to export an existing Workbook to a CSV file. The snippet creates a new workbook with a single worksheet. Further, it creates a `CsvFormatProvider` and invokes its `Export()` method:

**Example 2: Export CSV File**

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

string fileName = "SampleFile.csv";
CsvFormatProvider formatProvider = new CsvFormatProvider();

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

## See Also

* [IWorkbookFormatProvider API Reference](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider.html)
* [CsvFormatProvider API Reference](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Csv.CsvFormatProvider.html)
* [Import/Load and Export/Save RadSpreadProcessing Workbook](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/import-export-save-load-workbook)
* [Timeout Mechanism](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/timeout-mechanism-in-dpl)
* [Automatic Output Stream Clearing on Export](https://www.telerik.com/document-processing-libraries/documentation/common-information/clear-output-stream-on-export)
