Using the DataTableFormatProvider
The DataTableFormatProvider allows you to easily convert existing DataTable to a worksheet and vice versa. Below you can see how to use this format provider to import/export data tables.
To use the DataTableFormatProvider you need to reference the Telerik.Windows.Documents.Spreadsheet assembly.
Import
Example 1 shows how you can import a DataTable. The sample instantiates a DataTableFormatProvider and passes the table to its Import method.
Example 1: Import DataTable
DataTable table = GetTable();
DataTableFormatProvider provider = new DataTableFormatProvider();
Workbook workbook = provider.Import(table);
Example 2: Import DataTable to an existing Worksheet
DataTable table = GetTable();
DataTableFormatProvider provider = new DataTableFormatProvider();
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets.Add();
provider.Import(table, worksheet);
Export
Example 3 demonstrates how you can export an existing Worksheet to a DataTable. The snippet assumes that you already have a Workbook with some data.
Example 3: Export Worksheet to a DataTable
Workbook workbook = GetWorkbook();
DataTableFormatProvider provider = new DataTableFormatProvider();
DataTable table = provider.Export(workbook.ActiveWorksheet);