TL;DR: Syncfusion’s Excel Library provides a full-fledged object model that facilitates accessing and manipulating Excel documents without Microsoft Office or interop dependencies. Let’s learn to create Excel tables with this comprehensive tool in just three simple steps.
The [Syncfusion Excel Library](syncfusion.com/document-processing/excel-fr.. "Syncfusion Excel Library"), also known as Essential XlsIO, is a robust tool that facilitates the smooth creation, reading, and editing of Excel documents using C#. It supports the creation of Excel documents from scratch, modification of existing Excel documents, data import and export, Excel formulas, conditional formats, data validations, charts, sparklines, tables, pivot tables, pivot charts, template markers, and much more.
Enjoy a smooth experience with Syncfusion’s Excel Library! Get started with a few lines of code and without Microsoft or interop dependencies.
Explore Now
This blog will explore the steps to create an Excel table using the Syncfusion Excel Library and C#.
Note: Please refer to the [.NET Excel Library’s getting started documentation](help.syncfusion.com/file-formats/xlsio/crea.. "Create Excel File in C# and VB.NET") before proceeding.
Steps to create a table in Excel
Follow these steps to create a table in an Excel document using C#:
- First, create a [.NET Core Console application](docs.microsoft.com/en-us/dotnet/core/tutori.. "Create a .NET console application using Visual Studio") in [Visual Studio](visualstudio.microsoft.com/vs "Visual Studio"), as shown in the following image.
- Then, install the latest [Syncfusion.XlsIO.NET.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core "Syncfusion.XlsIO.Net.Core NuGet package") NuGet package to your app.
Now, add the following code to create a table in the existing Excel document.
using Syncfusion.XlsIO;
namespace ExcelTable { class Program { public static void Main() { Program program = new Program(); program.CreateTable(); }
///
/// Creates a table in the existing Excel document. /// public void CreateTable() { using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Xlsx; FileStream fileStream = new FileStream("../../../Data/SalesReport.xlsx", FileMode.Open, FileAccess.Read); IWorkbook workbook = application.Workbooks.Open(fileStream, ExcelOpenType.Automatic); IWorksheet worksheet = workbook.Worksheets[0];AddExcelTable("Table1", worksheet.UsedRange);
string fileName = "../../../Output/Table.xlsx";
//Saving the workbook as stream. FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite); workbook.SaveAs(stream); stream.Dispose(); } }
///
/// Adds a table to the worksheet with the given name and range. /// /// Table name /// Table range public void AddExcelTable(string tableName, IRange tableRange) { IWorksheet worksheet = tableRange.Worksheet;//Create a table with the data in a given range. IListObject table = worksheet.ListObjects.Create(tableName, tableRange);
//Set the table style. table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium14; } } }
Witness the possibilities in demos showcasing the robust features of Syncfusion’s C# Excel Library.
Try Now
Refer to the following images.
Input Excel document
Creating a table in an Excel document using Syncfusion .NET Excel Library and C#
Note: For more details, refer to [working with Excel table in C# documentation](help.syncfusion.com/file-formats/xlsio/work.. "Working with Excel Tables").
GitHub reference
You can also download the [example for creating a table in Excel using C# on GitHub](github.com/SyncfusionExamples/XlsIO-Example.. "Creating a table in Excel using C# GitHub demo").
Don't settle for ordinary spreadsheet solutions. Switch to Syncfusion and upgrade the way you handle Excel files in your apps!
Try It Free
Conclusion
Thanks for reading! In this blog, we explored how to create tables in Excel documents using C# and [Syncfusion Excel Library](syncfusion.com/excel-framework/net "Syncfusion Excel Library") (XlsIO). The Excel Library also allows you to export Excel data to [images](help.syncfusion.com/file-formats/xlsio/work.. "Worksheet to Image conversion in Excel Library"), [data tables](help.syncfusion.com/file-formats/xlsio/work.. "Exporting from Worksheet to Data Table"), [CSV](syncfusion.com/kb/9092/convert-excel-file-t.. "KB: Convert Excel file to CSV in C#, VB.NET"), [TSV](syncfusion.com/kb/8556/does-xlsio-support-t.. "KB: Does XlsIO support TSV files?"), [HTML](help.syncfusion.com/file-formats/xlsio/work.. "Save Worksheet as HTML"), [collections of objects](help.syncfusion.com/file-formats/xlsio/work.. "Working with Excel Data"), [ODS](help.syncfusion.com/file-formats/xlsio/exce.. "Excel to ODS Conversion"), [JSON](help.syncfusion.com/file-formats/xlsio/exce.. "Excel to JSON Conversion"), and other file formats.
Take a moment to peruse the [import data](help.syncfusion.com/file-formats/xlsio/work.. "Importing Data to Worksheets") documentation, where you’ll discover additional importing options and features such as [data tables](help.syncfusion.com/file-formats/xlsio/work.. "Import Data from DataTable"), [collection objects](help.syncfusion.com/file-formats/xlsio/work.. "Import Data from Collection Objects"), [grid view](help.syncfusion.com/file-formats/xlsio/work.. "Import Data from DataView"), [data columns](help.syncfusion.com/file-formats/xlsio/work.. "Importing Data from DataColumn"), and [HTML](help.syncfusion.com/file-formats/xlsio/work.. "Importing HTML Table to Excel Worksheet"), all accompanied by code samples.
Feel free to try out this versatile .NET Excel Library and share your feedback in the comments section of this blog post!
For existing customers, the new version of Essential Studio is available for download from the [License and Downloads](syncfusion.com/account/downloads "Essential Studio License and Downloads page") page. If you are not yet a Syncfusion customer, you can try our 30-day [free trial](syncfusion.com/downloads "Get the free 30-day evaluation of Essential Studio products") to check out our available features.
For questions, you can contact us through our [support forum](syncfusion.com/forums "Syncfusion Support Forum"), [support portal](support.syncfusion.com "Syncfusion Support Portal"), or [feedback portal](syncfusion.com/feedback "Syncfusion Feedback Portal"). We are always happy to assist you!
Related blogs
- [Print Excel Documents in Just 4 Steps Using C#](syncfusion.com/blogs/post/print-excel-in-cs.. "Blog: Print Excel Documents in Just 4 Steps Using C#")
- [Converting XLS to XLSX Format in Just 3 Steps Using C#](syncfusion.com/blogs/post/convert-xls-to-xl.. "Blog: Converting XLS to XLSX Format in Just 3 Steps Using C#")
- [Merge Multiple Excel Files into One in Just 3 Steps Using C#](syncfusion.com/blogs/post/merge-multiple-ex.. "Blog: Merge Multiple Excel Files into One in Just 3 Steps Using C#")
- [6 Easy Ways to Export Data to Excel in C#](syncfusion.com/blogs/post/6-easy-ways-to-ex.. "Blog: 6 Easy Ways to Export Data to Excel in C#")
- [Seamlessly Import and Export CSV Data in Excel Using C#](syncfusion.com/blogs/post/import-export-csv.. "Blog: Seamlessly Import and Export CSV Data in Excel Using C#")
- [Easy Steps to Export HTML Tables to Excel in C#](syncfusion.com/blogs/post/easy-steps-to-exp.. "Blog: Easy Steps to Export HTML Tables to Excel in C#")