![Preserving Table Formatting when Loading Excel files 1.png](images/Preserving_Table_Formatting_when_Loading_Excel_files_1.png)
This topic demonstrates how you can preserve table formatting when loading Microsoft Excel files.
This topic contains the following sections:
Each table has an associated style which provides default format settings for cells in many different areas of the table. This style is represented by the WorksheetTableStyle class and is exposed on a table through the WorksheetTable
's Style property. Preserving WorksheetTableStyles
is supported, so when you are loading Excel files, your table formatting will be preserved.
Code snippet below shows how Microsoft Excel table formats are preserved. It loads a Microsoft Excel file with tables in it and saves it under a different name, so you are able to compare files and assure that formatting is preserved.
The following screenshot is a preview of the final result.
An input stream to a Microsoft Excel file.
Random numbers in range C3:F6 and random names in range C2:F2 and B2:B6. Selection B2:F6 is formatted as Table with style Table Style Medium 3. This is done by selecting range and choosing Home -> Format as Table -> Table Style Medium 3.
Random numbers in range C8:F12 and random names in range C8:F8 and B8:B12. Selection B8:F12 is formatted as table with custom style. You can create custom style by choosing Home -> Format as Table -> New Table Style…
Empty table in region B14:F18. It is created by selecting B14:F18 and choosing Insert->Table. Microsoft Excel chooses as default style Table Style Medium 2.
The following code sample loads a Microsoft Excel file and saves it back under a different name.
In C#:
// Load a Workbook with tables in it
Infragistics.Documents.Excel.Workbook workbook = Infragistics.Documents.Excel.Workbook.Load(inputStream);
// Save the workbook under different name in order to compare with original source that table formats are preserved
workbook.Save(outputStream);
The following topics provide additional information related to this topic.
The following material (available outside the Infragistics family of content) provides additional information related to this topic.