Using XlsxFormatProvider
XlsxFormatProvider makes it easy to import and export XLSX (Excel Workbook) files. An XLSX 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.
Unlike the CSV and TXT format providers, the
XlsxFormatProviderrequires references to the following package:
- Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml
Starting with Q2 2025 the Zip Library is no longer used as an internal dependency in the rest of the Document Processing Libraries - PdfProcessing, WordsProcessing, SpreadProcessing, SpreadStreamProcessing. It is replaced by the System.IO.Compression. The Telerik Zip Library continues to ship as a standalone library so clients can still use it separately.
Once you reference the required package, create an instance of XlsxFormatProvider to import and export XLSX (Excel Workbook) files. This provider appears in the Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx namespace. XlsxFormatProvider implements the IWorkbookFormatProvider interface, which in turn appears in the Telerik.Windows.Documents.Spreadsheet.FormatProviders namespace. Depending on whether you want to work with the concrete class or the interface, you need to include either the first or both namespaces.
For more examples and application scenarios of importing and exporting a workbook to various formats using a format provider, check out the Import/Load and Export/Save RadSpreadProcessing Workbook knowledge base article.
Import
The following example shows how to import an XLSX file using a FileStream. The code verifies that a file with the specified name exists. The sample then creates an XlsxFormatProvider instance and passes a FileStream to its Import() method.
Example 1: Import XLSX (Excel Workbook) File
string fileName = "SampleFile.xlsx";
if (!File.Exists(fileName))
{
throw new FileNotFoundException(String.Format("File {0} was not found!", fileName));
}
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook;
XlsxFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
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 XLSX file. The snippet creates a new workbook with a single worksheet. It then creates an XlsxFormatProvider and calls 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 XLSX (Excel Workbook) File
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
workbook.Worksheets.Add();
string fileName = "SampleFile.xlsx";
Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
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 Array
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
workbook.Worksheets.Add();
Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();
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.