# Create and Format Excel Tables

Learn how to programmatically create and format Excel tables in C# .NET. Get started and see more from Document Solutions today.

## Content

This tutorial shows how to take raw XLSX worksheet data and convert it into a structured Excel Table in .NET applications using C# and a server-side Excel API library, **Document Solutions for Excel .NET (DsExcel .NET)**.
You’ll learn how to:

* Add a simple dataset to a worksheet
* Convert a range into an Excel table using the **[Worksheet.Tables.Add()](https://developer.mescius.com/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.ITables.Add.html "https://developer.mescius.com/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.ITables.Add.html") method**
* Apply a built-in TableStyle for a clean, formatted result

## Prerequisites

Before you begin, make sure you have:

* **.NET SDK**
* **Document Solutions for Excel .NET (DsExcel .NET)**
* The **[DS.Documents.Excel](https://www.nuget.org/packages/DS.Documents.Excel)**[ NuGet package](https://www.nuget.org/packages/DS.Documents.Excel) installed in your project

Install the package using the .NET CLI:

```bash
dotnet add package DS.Documents.Excel
```

Import the required namespace:

```csharp
using GrapeCity.Documents.Excel;
```

## 1) Create a Workbook and Worksheet (Minimal Setup)

This tutorial assumes you already know how to initialize a workbook, with a minimal setup shown below.

```csharp
Workbook workbook = new Workbook();
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Name = "Tables";
```

## 2) Add Sample Data to the Worksheet

We’ll start with a small dataset (header row + values), then place it into a worksheet range.

```csharp
object[,] sourceData = new object[,]
{
    {"ITEM", "AMOUNT"},
    {"Income 1", 2500},
    {"Income 2", 1000},
    {"Income 3", 250},
    {"Other", 250},
};

worksheet.Range["B3:C7"].Value = sourceData;
```

At this stage, the worksheet contains raw values, but it is not yet a structured Excel table.

## 3) Convert the Range into an Excel Table

Use the **[Worksheet.Tables.Add()](https://developer.mescius.com/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.ITables.Add.html "https://developer.mescius.com/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.ITables.Add.html") method** to convert the data range into a structured table.
The second argument set to **true** indicates the range includes a header row.

```csharp
ITable incomeTable = worksheet.Tables.Add(worksheet.Range["B3:C7"], true);
incomeTable.Name = "tblIncome";
```

## 4) Apply a Built-In Table Style

Once the range is a table, you can apply a predefined Excel table style.

```csharp
incomeTable.TableStyle = TableStyle.TableStyleMedium4;
```

## Visual Outcome (Formatted Excel Table)

After converting the range into a table and applying a style, the worksheet will display:

* A styled header row
* Alternating row shading (depending on style)
* Table filtering dropdowns in the header row
* A structured table object that Excel recognizes as a real table

![image](https://cdn.mescius.io/document-site-files/images/6c089d65-4816-4591-8c0d-bb0bfb8c43df/image-20260713.b9174e.png)

## 5) Save the Workbook

You can save the workbook in XLSX format with the following code:

```csharp
workbook.Save("ExcelTables.xlsx");
```

## Next Steps

* Read the [full table documentation here](https://developer.mescius.com/document-solutions/dot-net-excel-api/docs/online/Features/UseTable "https://developer.mescius.com/document-solutions/dot-net-excel-api").
* Explore a [full demo showcasing tables here](https://developer.mescius.com/document-solutions/dot-net-excel-api/demos/tables "https://developer.mescius.com/document-solutions/dot-net-excel-api/demos/").