3 Simple Steps to Split an Excel File into Multiple Excel Files in C#
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (206)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (214)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (132)JavaScript  (220)Microsoft  (118)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (911)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (158)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (130)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (624)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (6)Gantt  (18)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  (504)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (386)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (588)What's new  (329)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Split Excel document into multiple Excel files in just 3 Steps Using csharp

3 Simple Steps to Split an Excel File into Multiple Excel Files in C#

Managing Excel documents can be challenging, especially when they are large or contain multiple sheets with diverse data. Navigating and managing the information within a single document can become increasingly difficult. A practical solution to this issue is to divide these extensive Excel documents into several smaller ones, for manageability and efficiency.

The Syncfusion Excel Library (XlsIO) is a powerful tool designed to streamline the creation, reading, and editing of Excel documents using C#. It provides a simple and efficient way to handle Excel documents. With just a few lines of code, you can open an Excel document and split it into multiple smaller documents. This automation saves valuable time and ensures the precision of data. This library is particularly useful for those who frequently work with large datasets in Excel and are looking for ways to improve their productivity and data management.

So, let’s see how to split an Excel file into multiple Excel files using the Syncfusion Excel Library in C#.

Enjoy a smooth experience with Syncfusion’s Excel Library! Get started with a few lines of code and without Microsoft or interop dependencies.

Split Excel file with C#

Follow these steps to split an Excel file into multiple files.

Step 1: Initiate Visual Studio

First, we will start by launching Visual Studio.

Step 2: Set up a new .NET Core console application

The next step is to establish a new project. This will be a .NET Core console application. You can accomplish this by adhering to the instructions in this getting started document. It will navigate you through the process, ensuring your project is set up accurately.

Refer to the following image.Create a .NET Core Console application

Step 3: Incorporate the Syncfusion Excel Library

Before you delve into coding, install the Syncfusion Excel Library. Navigate to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution. In the NuGet Package Manager’s search bar, input Syncfusion.XlsIO.Net.Core and press Enter. Once the library pops up in the search results, click Install to integrate it into your project.Install Syncfusion.XlsIO.Net.Core NuGet package

Witness the possibilities in demos showcasing the robust features of Syncfusion’s C# Excel Library.

Step 4: Inject the namespace and craft the split function

With everything in place, it’s time to commence coding. You will need to inject the necessary code into the Program.cs file to split an Excel document from a specified folder path. This involves incorporating a suitable namespace and the function that executes the splitting operation.

Refer to the following code example.

using Syncfusion.XlsIO;

namespace SplitExcel
    class Program
        private static string inputPath = @"../../../Data/";

        private static string outputPath = @"../../../Output/";
        static void Main(string[] args)
            string fileName = "Report.xlsx";

            //Split the Excel document.
            SplitExcelDocument(inputPath + fileName);
        /// <summary>
        /// Split the Excel document from the given path.
        /// </summary>
        /// <param name="filePath">Excel file path</param>
        private static void SplitExcelDocument(string filePath)
            FileStream inputData = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);

            using (ExcelEngine excelEngine = new ExcelEngine())
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Xlsx;
                IWorkbook workbook = application.Workbooks.Open(inputData);
                IWorksheets worksheets = workbook.Worksheets;

                workbook.Version = ExcelVersion.Xlsx;

                //Loop through each Excel worksheet and save it as a new workbook.
                foreach (IWorksheet worksheet in worksheets)
                    IWorkbook newBook = application.Workbooks.Create(0);

                    FileStream outputData = new FileStream(outputPath + worksheet.Name + ".xlsx", FileMode.Create, FileAccess.ReadWrite);

The following image shows the input Excel document.

Input Excel document
Input Excel document

After executing the previous code example, the output documents will look like the following images. See the number of Excel documents created from the original Excel file.Output Excel document

Output Excel document

Output excel documentSplitting an Excel document into multiple Excel documents using Syncfusion Excel Library in C#

GitHub samples

You can download the example for splitting Excel documents in C# on this GitHub page.

From simple data tables to complex financial models, Syncfusion empowers you to unleash your creativity and design stunning Excel spreadsheets.

Wrapping up

Thanks for reading! We’ve explored how the Syncfusion Excel Library can simplify splitting an Excel document into multiple Excel documents using C#. I encourage you to explore the documentation further, where you’ll find various import options and features such as  data tablescollection objectsgrid viewdata columns, and HTML, all accompanied by helpful code samples.

The Excel Library also allows you to export Excel data to various file formats, including PDFsimagesdata tablesCSVTSVHTMLcollections of objectsODSJSON, and more.

If you’re new to our Excel Library, we recommend following our Getting Started guide. For existing Syncfusion users, you can download the product setup directly here. If you’re not yet a Syncfusion user, we offer a free 30-day trial for you to explore and evaluate our products.

If you have any questions or need further clarification on these features, feel free to leave a comment below. You can also contact us through our support forum, support portal, or feedback portal. We’re always here to help you!

Related blogs


Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed