Version

Preserving Table Formatting When Loading Excel Files (Infragistics Excel Engine)

Topic Overview

Purpose

This topic demonstrates how you can preserve table formatting when loading Microsoft Excel files.

In this topic

This topic contains the following sections:

Introduction

Overview

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 Example: Preserving Formatting While Loading Excel Tables

Description

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.

Preview

The following screenshot is a preview of the final result.

Preserving Table Formatting when Loading Excel files 1.png

Prerequisites

  • A Microsoft Excel file named Book4.xlsx with a worksheet saved at your C: hard drive.

  • 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.

Code

The following code sample loads a Microsoft Excel file and saves it back under a different name.

In Visual Basic:

' Load a Workbook with tables in it
Dim workbook As Infragistics.Documents.Excel.Workbook = Infragistics.Documents.Excel.Workbook.Load("C:\Book4.xlsx")
' Save the workbook under different name in order to compare with original source that table formats are preserved
workbook.Save("C:\Book4-TableFormatPreserved.xlsx")

In C#:

// Load a Workbook with tables in it
Infragistics.Documents.Excel.Workbook workbook = Infragistics.Documents.Excel.Workbook.Load("C:\\Book4.xlsx");
// Save the workbook under different name in order to compare with original source that table formats are preserved
workbook.Save("C:\\Book4-TableFormatPreserved.xlsx");

Related Content

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic describes the creating and accessing of named tables.

In this section you’ll find information that will help you to better understand the object model and the functionalities of the Infragistics Excel Engine.

Resources

The following material (available outside the Infragistics family of content) provides additional information related to this topic.

Title Purpose

Gives information about creating/deleting a table and converting a table to a range of data.