3 Simple Steps to Split an Excel File into Multiple Excel Files in C#
Tags: fileformats, csharp, excel, data
Published: 2024-01-19 12:42:47

---
title: 3 Simple Steps to Split an Excel File into Multiple Excel Files in C#
published: true
date: 2024-01-17 16:41:38 UTC
tags: fileformats, csharp, excel, data
canonical_url: https://www.syncfusion.com/blogs/post/split-excel-file-csharp.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4x800rj9t5medmufh7g.png
---
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](https://www.syncfusion.com/document-processing/excel-framework/net ".NET 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#.

## Split Excel file with CSharp

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

### Step 1: Initiate Visual Studio

First, we will start by launching [Visual Studio](https://visualstudio.microsoft.com/ "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](https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-8-0 "Create a .NET console app using Visual Studio"). 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](https://www.syncfusion.com/blogs/wp-content/uploads/2024/01/Create-a-.NET-Core-Console-application-1.png)

### 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](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core "Syncfusion.XlsIO.Net.Core NuGet Package") 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](https://www.syncfusion.com/blogs/wp-content/uploads/2024/01/Install-Syncfusion.XlsIO_.Net_.Core-NuGet-package.png)

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

```csharp
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);
                    newBook.Worksheets.AddCopy(worksheet);

                    FileStream outputData = new FileStream(outputPath + worksheet.Name + ".xlsx", FileMode.Create, FileAccess.ReadWrite);
                    newBook.SaveAs(outputData);
                    outputData.Close();
                }
            }
        }
    }
}
```

The following image shows the input Excel document.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2024/01/Input-Excel-document-1.png" alt="Input Excel document" style="width:100%">

  <figcaption>Input Excel document</figcaption>

</figure>

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](https://www.syncfusion.com/blogs/wp-content/uploads/2024/01/Input-Excel-document-2.png)

![Output Excel document](https://www.syncfusion.com/blogs/wp-content/uploads/2024/01/Input-Excel-document-3.png)

![Output excel document](https://www.syncfusion.com/blogs/wp-content/uploads/2024/01/Input-Excel-document-4.png)<figcaption>Splitting an Excel document into multiple Excel documents using Syncfusion Excel Library in C#</figcaption>

## GitHub samples

You can download the example for splitting Excel documents in C# on [this GitHub page](https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/Real%20Time%20Examples%20in%20Excel/SplitExcelDocument "Split excel document using C# GitHub demo").

## Wrapping up

Thanks for reading! We’ve explored how the [Syncfusion Excel Library](https://www.syncfusion.com/excel-framework/net ".NET Excel Library") can simplify splitting an Excel document into multiple Excel documents using C#. I encourage you to explore the [documentation](https://help.syncfusion.com/file-formats/xlsio/working-with-data#importing-data-to-worksheets "Importing Data to Worksheets") further, where you’ll find various import options and features such as  [data tables](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datatable "Import Data from DataTable"), [collection objects](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-collection-objects "Import Data from Collection Objects"), [grid view](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-dataview "Import Data from DataView"), [data columns](https://help.syncfusion.com/file-formats/xlsio/working-with-data#import-data-from-datacolumn "Importing Data from DataColumn"), and [HTML](https://help.syncfusion.com/file-formats/xlsio/working-with-data#importing-html-table-to-excel-worksheet "Importing HTML Table to Excel Worksheet"), all accompanied by helpful code samples.

The Excel Library also allows you to export Excel data to various file formats, including [PDFs](https://help.syncfusion.com/file-formats/xlsio/excel-to-pdf-conversion "Excel to PDF Conversion"), [images](https://help.syncfusion.com/file-formats/xlsio/worksheet-to-image-conversion "Worksheet to Image conversion"), [data tables](https://help.syncfusion.com/file-formats/xlsio/working-with-data#exporting-from-worksheet-to-data-table "Exporting from Worksheet to Data Table"), [CSV](https://www.syncfusion.com/kb/9092/convert-excel-file-to-csv-in-c-vb-net "Convert Excel file to CSV"), [TSV](https://www.syncfusion.com/kb/8556/does-xlsio-support-tsv-files "Excel to TSV conversion"), [HTML](https://help.syncfusion.com/file-formats/xlsio/working-with-excel-worksheet?_ga=2.19528508.561950334.1598519523-255771547.1598519523#save-worksheet-as-html "Save Worksheet as HTML"), [collections of objects](https://help.syncfusion.com/file-formats/xlsio/working-with-data#exporting-from-worksheet-to-clr-objects "Working with Excel Data"), [ODS](https://help.syncfusion.com/file-formats/xlsio/excel-to-ods-conversion "Excel to ODS Conversion"), [JSON](https://help.syncfusion.com/file-formats/xlsio/excel-to-json-conversion "Excel to JSON Conversion"), and more.

If you’re new to our Excel Library, we recommend following our [Getting Started guide](https://help.syncfusion.com/file-formats/xlsio/getting-started-create-excel-file-csharp-vbnet "Create Excel File in C#"). For existing Syncfusion users, you can download the product setup directly [here](https://www.syncfusion.com/account/downloads/studio/ "Essential Studio License and Downloads page"). If you’re not yet a Syncfusion user, we offer a free [30-day trial](https://www.syncfusion.com/downloads/fileformats/confirm "Get free evaluation of Essential Studio products") 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](https://www.syncfusion.com/forums "Syncfusion Support Forum"), [support portal](https://support.syncfusion.com/ "Syncfusion Support Portal"), or [feedback portal](https://www.syncfusion.com/feedback "Syncfusion Feedback Portal"). We’re always here to help you!

## Related blogs

- [Merge Multiple Excel Files into One in Just 3 Steps Using C#](https://www.syncfusion.com/blogs/post/merge-multiple-excel-csharp.aspx "Blog: Merge Multiple Excel Files into One in Just 3 Steps Using C#")
- [6 Easy Ways to Export Data to Excel in C#](https://www.syncfusion.com/blogs/post/6-easy-ways-to-export-data-to-excel-in-c-sharp.aspx "Blog: 6 Easy Ways to Export Data to Excel in C#")
- [Seamlessly Import and Export CSV Data in Excel Using C#](https://www.syncfusion.com/blogs/post/import-export-csv-data-in-excel-csharp.aspx "Blog: Seamlessly Import and Export CSV Data in Excel Using C#")
- [How to Export Data from SQL Server to an Excel Table in C#](https://www.syncfusion.com/blogs/post/export-data-from-sql-server-to-excel-in-c-sharp.aspx "Blog: How to Export Data from SQL Server to an Excel Table in C#")
- [Export Data from a Collection to Excel and Group It in C# ](https://www.syncfusion.com/blogs/post/export-data-from-collection-to-excel-and-group-csharp.aspx "Blog: Export Data from a Collection to Excel and Group It in C#")
- [Export Data to a Predefined Excel Template in C#](https://www.syncfusion.com/blogs/post/export-data-to-a-predefined-excel-template-in-c.aspx "Blog: Export Data to a Predefined Excel Template in C#")
- [Easy Steps to Export HTML Tables to Excel in C#](https://www.syncfusion.com/blogs/post/easy-steps-to-export-html-tables-to-an-excel-worksheet-in-c.aspx "Blog: Easy Steps to Export HTML Tables to Excel in C#")