# Using XlsFormatProvider

`XlsFormatProvider` makes it easy to import and export XLS (Excel 97-2003 Workbook) files. The functionality is available starting with R3 2020.

> The `XlsFormatProvider` requires references to the following packages:

> * Telerik.Windows.Documents.Spreadsheet.FormatProviders.Xls for .NET Framework projects
> * Telerik.Documents.Spreadsheet.FormatProviders.Xls for .NET Standard projects

After you reference these packages, create an instance of the `XlsFormatProvider` to import and export Excel 97-2003 Workbook files. This provider appears in the `Telerik.Windows.Documents.Spreadsheet.FormatProviders.Xls` namespace. `XlsFormatProvider` implements the `IWorkbookFormatProvider` interface, which in turn appears in `Telerik.Windows.Documents.Spreadsheet.FormatProviders`. Depending on whether you work with the concrete class or the interface, include either the first or both namespaces.

> note For more examples and application scenarios of importing and exporting a workbook to various formats, see 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

The following example shows how to import an XLS file through a `FileStream`. The code verifies that a file with the specified name exists. The sample creates an `XlsFormatProvider` instance and passes a `FileStream` to its `Import()` method.

**Example 1: Import XLS (Excel 97-2003 Workbook) File**

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

Telerik.Documents.Spreadsheet.Model.Workbook workbook;
Telerik.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider();

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

## Export

The following example demonstrates how to export an existing workbook to an XLS file. The snippet creates a new workbook with a single worksheet. The example then creates an `XlsFormatProvider` instance and invokes its `Export()` method. The `Export()` method accepts a parameter of type `Stream` so you can work with any of its inheritors.

**Example 2: Export Spreadsheet Document to XLS (Excel 97-2003 Workbook) File**

```C#
Telerik.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Documents.Spreadsheet.Model.Workbook();
workbook.Worksheets.Add();
string fileName = "SampleFile.xls";

Telerik.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider();

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

**Example 3: Export a workbook to a memory stream and capture the XLS bytes**

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

Telerik.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.Xls.XlsFormatProvider();

byte[] bytes;
using (MemoryStream output = new MemoryStream())
{
    formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
    bytes = output.ToArray();
}
```

\*This documentation is neither affiliated with, nor authorized, sponsored, or approved by, Microsoft Corporation.

## See Also

* [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)
