Create Excel Table in Just 3 Steps Using C#
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (182).NET Core  (27).NET MAUI  (233)Angular  (117)ASP.NET  (49)ASP.NET Core  (81)ASP.NET MVC  (87)Azure  (42)Black Friday Deal  (1)Blazor  (244)BoldSign  (15)DocIO  (24)Essential JS 2  (109)Essential Studio  (200)File Formats  (74)Flutter  (140)JavaScript  (227)Microsoft  (121)PDF  (86)Python  (1)React  (107)Streamlit  (1)Succinctly series  (131)Syncfusion  (991)TypeScript  (33)Uno Platform  (3)UWP  (3)Vue  (46)Webinar  (53)Windows Forms  (59)WinUI  (72)Word  (9)WPF  (165)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (11)Business intelligence  (55)Button  (4)C#  (164)Chart  (154)Chart of the week  (62)Cloud  (16)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (74)Development  (694)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (43)Extensions  (31)File Manager  (8)Gantt  (23)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (530)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (48)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (426)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (648)What's new  (354)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

Create Excel Table in Just 3 Steps Using C#

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

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 before proceeding.

Steps to create a table in Excel

Follow these steps to create a table in an Excel document using C#:

  1. First, create a .NET Core Console application in Visual Studio, as shown in the following image.
    Create a .NET Core Console application
  2. Then, install the latest Syncfusion.XlsIO.NET.Core NuGet package to your app.Install Syncfusion.XlsIO.Net.Core NuGet
  3. 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();
            }
    
            /// <summary>
            /// Creates a table in the existing Excel document.
            /// </summary>
            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();
                }
            }
    
            /// <summary>
            /// Adds a table to the worksheet with the given name and range.
            /// </summary>
            /// <param name="tableName">Table name</param>
            /// <param name="tableRange">Table range</param>
            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.

Refer to the following images.

Input Excel document
Input Excel document
Creating a table in an Excel document using Syncfusion .NET Excel Library and C#
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.

GitHub reference

You can also download the example for creating a table in Excel using C# on GitHub.

Don't settle for ordinary spreadsheet solutions. Switch to Syncfusion and upgrade the way you handle Excel files in your apps!

Conclusion

Thanks for reading! In this blog, we explored how to create tables in Excel documents using C# and Syncfusion Excel Library (XlsIO). The Excel Library also allows you to export Excel data to imagesdata tablesCSVTSVHTML, collections of objectsODSJSON, and other file formats.

Take a moment to peruse the import data documentation, where you’ll discover additional importing options and features such as data tablescollection objectsgrid viewdata columns, and HTML, 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 page. If you are not yet a Syncfusion customer, you can try our 30-day free trial to check out our available features.

For questions, you can contact us through our support forumsupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed