New to Telerik Document ProcessingStart a free 30-day trial

Using XlsmFormatProvider

Updated on Jun 16, 2026

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.

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.

For more examples and application scenarios of importing and exporting a workbook to various formats, see the Import/Load and Export/Save RadSpreadProcessing 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.Windows.Documents.Spreadsheet.Model.Workbook workbook;
Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider formatProvider = new Telerik.Windows.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: Export Spreadsheet Document to XLSM (Excel Workbook) File

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


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

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

Example 3: Export Spreadsheet Document to a Stream and byte[]

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

Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsm.XlsmFormatProvider formatProvider = new Telerik.Windows.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

In this article
ImportExportSee Also
Not finding the help you need?
Contact Support