# Using XlsmFormatProvider

`XlsmFormatProvider` makes it easy to import and export XLSM (Excel Workbook that supports macros) files. An XLSM file is a group of zipped files that conform to the Office Open XML schema. The format allows you to export all parts of a workbook: worksheets, formula values, formatting, hyperlinks, and more.

> Currently, macros are only preserved during import and export. They cannot be executed or changed in the code.

> Unlike the CSV and TXT format providers, the `XlsmFormatProvider` requires references to the following packages:
>
> * Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.

> note Starting with **Q2 2025**, the Zip Library will no longer be used as an internal dependency in the rest of the Document Processing Libraries - PdfProcessing, WordsProcessing, SpreadProcessing, SpreadStreamProcessing. It will be replaced by System.IO.Compression. The Telerik Zip Library will continue to ship as a standalone library so you can still use it separately.

After you reference these packages, create an instance of the `XlsmFormatProvider` to import and export XLSM (Excel Workbook) files. This provider appears in the `Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm` namespace. `XlsmFormatProvider` 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 XLSM file through a `FileStream`. The code verifies that a file with the specified name exists. The sample creates an `XlsmFormatProvider` instance and passes a `FileStream` to its `Import()` method.

**Example 1: Import XLSM (Excel Workbook) File**

```C#
string fileName = "SampleFile.Xlsm";
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.OpenXml.Xlsm.XlsmFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();

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 XLSM file. The snippet creates a new workbook with a single worksheet. The example then creates an `XlsmFormatProvider` instance and invokes its `Export()` method. The `Export()` method accepts a parameter of type `Stream` so you can work with any of its inheritors.

> Exporting a workbook created with RadSpreadProcessing produces a file with empty macros (VBA Project).

**Example 2: Create a workbook and export it to an XLSM file stream**

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


Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();

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 XLSM bytes**

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

Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider formatProvider = new Telerik.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider();

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

## 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)
