C#: Online Guide
How To: excel SDK
File: Split Excel Document
File: Split Excel Document
Home ›› XDoc.Excel ›› C# Excel: Split Excel Document

C# Excel - Split Excel Document in C#.NET

Explain How to Split Excel Document in Visual C#.NET Application


C# Excel document splitting library control, XDoc.Excel, provides an advanced C# programming way to split Excel document into smaller Excel files in .NET developing applications. Using this C#.NET Excel document splitting library control, C# developers can easily and accurately disassemble multi-page Excel document into two or more separate Excel document files by page(s).

Related .net document control helps:
asp.net create pdf: ASP.NET Create PDF Document Control: create, convert PDF file from Word, Excel, Tiff file formats in C# ASP.NET
asp.net convert pdf: ASP.NET Convert PDF Control: Convert, export PDF to Word, HTML, Tiff files in C# ASP.NET
asp.net excel document viewer: ASP.NET Excel Document Viewer in C# Control: view office excel files online in ASP.NET web applications
asp.net edit pdf text: ASP.NET PDF Text Edit Control: online edit PDF text content using C# ASP.NET
asp.net powerpoint document viewer: ASP.NET PowerPoint Document Viewer Control: view pptx files online in C# using ASP.NET
view document asp.net: View multiple document formats in ASP.NET, MVC, Ajax, Azure using C# control
asp.net edit pdf image: ASP.NET PDF Image Edit Control: online insert, edit PDF images in C#

RasterEdge Visual C# .NET Excel document splitter control toolkit SDK can not only offer C# developers a professional .NET solution to split Excel document file but also provide them the ability to name outputted Excel document files with a customized name pattern using a few lines of simple Visual C# code.

This C#.NET Excel document splitting library control offers developers an efficient Excel document splitting approach, using which C# developers can split target Excel document file by specifying a page or pages. If needed, developers can also combine generated split Excel document files with other Excel files to form a new Excel file using RasterEdge XDoc.Excel. Besides, in the process of splitting Excel document, developers can also remove certain Excel page from target Excel file using C#.NET Excel page deletion API.

Please note, Excel file will be divided from the previous page of your defined page number which starts from 0. For example, your original Excel file contains 4 pages. If your page number is set as 1, then the two output Excel files will contains the first page and the later three pages respectively.

C# DLLs: Split Excel Document

Add necessary references:










Using namespaces:

  using RasterEdge.Imaging.Basic;

  using RasterEdge.XDoc.Excel;

Split Excel file into two files in C#

This is an C# example of splitting a Excel file into multiple ones by number of pages.

String inputFilePath = Program.RootPath + "\\" + "1.xlsx";
String outputFilePath1 = Program.RootPath + "\\" + "Split1.xlsx";
String outputFilePath2 = Program.RootPath + "\\" + "Split2.xlsx";
String[] outputOps = new  String[] { outputFilePath1, outputFilePath2 };
//  split a Excel file with options
XLSXDocument.SplitDocument(inputFilePath, 2, outputOps);

Split Excel Document into Multiple Excel Files in C#

You can use the following C# demo to split Excel document to four files.

String inputFilePath = Program.RootPath + "\\" + "1.xlsx";
String outputFileName = "Output.xlsx";
int[] splitIndex = new int[3] { 1, 3, 5 }; // Valid value for each index: 1 to (Page Count - 1).

// Create output Excel file path list
List<String> outputFilePaths = new List<String>();
for (int i = 0; i <= splitIndex.Length; i++)
        outputFilePaths.Add(Program.RootPath + "\\" + outputFileName + "_" + i.ToString() + ".xlsx");

// Split input Excel file to 4 files:
// File 0: page 0.
// File 1: page 1 ~ 2.
// File 2: page 3 ~ 4.
// File 3: page 5 ~ the last page.
XLSXDocument.SplitDocument(inputFilePath, splitIndex, outputFilePaths.ToArray());