Version

Adding a Table to a Worksheet (Infragistics Excel Engine)

Topic Overview

Purpose

This topic provides procedural instructions on how to add a worksheet table to a worksheet using the Infragistics Excel Engine.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

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

In order to get you up and running as quickly as possible with the Infragistics Excel Engine, this topic provides procedural instructions on how to create a workbook.

In this topic

This topic contains the following sections:

Adding a Table to a Worksheet

Introduction

The worksheet tables are a related data in the worksheet formatted in rows and columns. The data in a worksheet table can be managed independently from the data in the other rows and columns of the worksheet. Worksheet tables in the Infragistics Excel Engine are represented by the WorksheetTable class and are added in the worksheet’s Tables collection. This procedure demonstrates how to add a worksheet table to a worksheet.

Prerequisites

To complete the procedure, you need the following:

An initialized workbook with at least one worksheet named "ws".

Overview

Following is a conceptual overview of the process:

  1. Invoke the Add method of the Worksheet’s Tables collection

  2. Specify table’s region

  3. Specify if the table data contains headers

  4. Specify table’s style (optional)

Steps

The following steps demonstrate how to add a table to a worksheet.

1. Invoke the Add method of the Worksheet’s Tables collection

Invoke the Add method of the Worksheet’s Tables collection. The next steps provide more information regarding the method’s arguments.

2. Specify table’s region

As first argument specify the region which should be occupied by the table. For example: "F16:T29". If your data have headers include the header cells in the region too.

3. Specify if the table data contains headers

As second argument specify if the specified region contains cells which should be used as table headers. Set this argument to true if there are header cells in the region.

4. Specify table’s style (optional)

As third and optional argument you can specify a WorksheetTableStyle object to apply on the table.

Full code

The following code demonstrates how to add a worksheet table (which occupies the region "F16:T29" and has header cells in the top cells of this region) to the Tables collection of a worksheet named "ws".

In Visual Basic:

Dim wt As WorksheetTable = Me.ws.Tables.Add("F16:T29", True)

In C#:

WorksheetTable wt = this.ws.Tables.Add("F16:T29", true);
Note
Note

You can use the reference returned by the Add method to operate with the worksheet table. For example you may set a table name, obtain its regions or provide sort settings.

Alter Table Columns and Rows

The following table explains briefly the altering operations you may perform over the columns and rows of a worksheet table and maps them to the methods that configure them.

Altering operation Details Method

Insert column(s)

This method is used to insert one or more column(s).

Insert data row(s)

This method is used to insert one or more data row(s)

Delete column(s)

This method is used to delete one or more column(s)

Delete data row(s)

This method is used to delete one or more data row(s).

Set new table range

This method is used to assign a new cells' region to a WorksheetTable object. For example if you have a WorksheetTable object assigned to the cells' region C26:G32 you can reassign the WorksheetTable object to cells' region J6:O15 by invoking:

In Visual Basic:

worksheetTable.Resize("J6:O15")

In C#:

worksheetTable.Resize("J6:O15");

The cells' region at location C26:G32 will retain their content and styling, but will not be associated with the WorksheetTable object any more.

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic describes how to filter columns in exported tables.

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

This topic describes how to sort columns in exported tables.

This topic describes the creating and accessing of named tables.