diff --git a/Editing Excel cells/Replace/.NET/Replace/README.md b/Editing Excel cells/Replace/.NET/Replace/Replace/README.md similarity index 100% rename from Editing Excel cells/Replace/.NET/Replace/README.md rename to Editing Excel cells/Replace/.NET/Replace/Replace/README.md diff --git a/Editing Excel cells/Set Cell Values/.NET/Set Cell Values/Set Cell Values/README.md b/Editing Excel cells/Set Cell Values/.NET/Set Cell Values/Set Cell Values/README.md new file mode 100644 index 00000000..33663119 --- /dev/null +++ b/Editing Excel cells/Set Cell Values/.NET/Set Cell Values/Set Cell Values/README.md @@ -0,0 +1,76 @@ +# Edit Excel document using C# + +The [.NET Excel Library](https://www.syncfusion.com/document-sdk/net-excel-library) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. + +## Steps to edit an Excel document programmatically + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. +```csharp +using System.IO; +using Syncfusion.XlsIO; +``` +Step 5: Include the below code snippet in **Program.cs** to edit an Excel document. +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); + IWorksheet sheet = workbook.Worksheets[0]; + + sheet.Range["D1"].Text = "In Stock"; + sheet.Range["E1"].Text = "Total Price"; + sheet.Range["F1"].Text = "Discount (10%)"; + sheet.Range["G1"].Text = "Final Price"; + + sheet.Range["D2"].Boolean = true; + sheet.Range["D3"].Boolean = true; + + sheet.Range["A4"].Text = "Bag"; + sheet.Range["B4"].Number = 500; + sheet.Range["C4"].Number = 5; + sheet.Range["D4"].Boolean = false; + + sheet.Range["A5"].Text = "Bottle"; + sheet.Range["B5"].Number = 100; + sheet.Range["C5"].Number = 10; + sheet.Range["D5"].Boolean = true; + + sheet.Range["E2"].Formula = "B2*C2"; + sheet.Range["F2"].Formula = "E2*0.1"; + sheet.Range["G2"].Formula = "E2-F2"; + + sheet.Range["E3"].Formula = "B3*C3"; + sheet.Range["F3"].Formula = "E3*0.1"; + sheet.Range["G3"].Formula = "E3-F3"; + + sheet.Range["E4"].Formula = "B4*C4"; + sheet.Range["F4"].Formula = "E4*0.1"; + sheet.Range["G4"].Formula = "E4-F4"; + + sheet.Range["E5"].Formula = "B5*C5"; + sheet.Range["F5"].Formula = "E5*0.1"; + sheet.Range["G5"].Formula = "E5-F5"; + + sheet.Range["A6"].Text = "Totals"; + sheet.Range["E6"].Formula = "SUM(E2:E5)"; + sheet.Range["F6"].Formula = "SUM(F2:F5)"; + sheet.Range["G6"].Formula = "SUM(G2:G5)"; + + sheet.Range["A1:G1"].CellStyle.Font.Bold = true; + sheet.Range["A1:G6"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter; + + IListObject table = sheet.ListObjects.Create("SalesTable", sheet.Range["A1:G6"]); + table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium23; + + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); + workbook.Close(); +} +``` diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET Core/MergeExcel/README.md b/Real Time Examples in Excel/Merge Excel Documents/.NET Core/MergeExcel/README.md new file mode 100644 index 00000000..25b4c25c --- /dev/null +++ b/Real Time Examples in Excel/Merge Excel Documents/.NET Core/MergeExcel/README.md @@ -0,0 +1,42 @@ +# Merge Multiple Excel Files into One Excel File in C# + +The [.NET Excel Library](https://www.syncfusion.com/document-sdk/net-excel-library) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can **merge multiple Excel files into one Excel file** using C#. + +## Steps to Merge Multiple Excel Files into One Excel File + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. +```csharp +using System.IO; +using Syncfusion.XlsIO; +``` +Step 5: Include the below code snippet in **Program.cs** to merge multiple Excel files into one Excel file +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(0); + + //Loop through each Excel document and add the worksheets to the new workbook + foreach (Stream stream in streams) + { + stream.Position = 0; + IWorkbook tempWorkbook = application.Workbooks.Open(stream); + workbook.Worksheets.AddCopy(tempWorkbook.Worksheets); + tempWorkbook.Close(); + } + + //Save the workbook to a memory stream + MemoryStream memoryStream = new MemoryStream(); + workbook.Version = ExcelVersion.Xlsx; + workbook.SaveAs(memoryStream); + + return memoryStream; +} +``` \ No newline at end of file diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel.sln b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel.sln new file mode 100644 index 00000000..61033c22 --- /dev/null +++ b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34310.174 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MergeExcel", "MergeExcel\MergeExcel.csproj", "{B68720C9-71D9-4706-B1E2-7C207699EF1D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B68720C9-71D9-4706-B1E2-7C207699EF1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B68720C9-71D9-4706-B1E2-7C207699EF1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B68720C9-71D9-4706-B1E2-7C207699EF1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B68720C9-71D9-4706-B1E2-7C207699EF1D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C8553F0E-B638-4BC4-9E5B-2FC2C818FB4A} + EndGlobalSection +EndGlobal diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/First.xlsx b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/First.xlsx new file mode 100644 index 00000000..876c6e05 Binary files /dev/null and b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/First.xlsx differ diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/Second.xlsx b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/Second.xlsx new file mode 100644 index 00000000..e3952d07 Binary files /dev/null and b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/Second.xlsx differ diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/Third.xlsx b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/Third.xlsx new file mode 100644 index 00000000..2ea0162b Binary files /dev/null and b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Data/Third.xlsx differ diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/MergeExcel.csproj b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/MergeExcel.csproj new file mode 100644 index 00000000..b7de65a3 --- /dev/null +++ b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/MergeExcel.csproj @@ -0,0 +1,35 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + Always + + + Always + + + + + + + + + + + diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Output/.gitkeep b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Output/MergedExcel.xlsx b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Output/MergedExcel.xlsx new file mode 100644 index 00000000..48a3eddd Binary files /dev/null and b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Output/MergedExcel.xlsx differ diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Program.cs b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Program.cs new file mode 100644 index 00000000..bba2113d --- /dev/null +++ b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Program.cs @@ -0,0 +1,70 @@ +// See https://aka.ms/new-console-template for more information +using Syncfusion.XlsIO; + + +namespace MergeExcel +{ + class Program + { + static void Main(string[] args) + { + string inputPath = @"../../../Data/"; + + string outputPath = @"../../../Output/"; + + FileInfo[] files = new DirectoryInfo(inputPath).GetFiles(); + + List streams = new List(); + + foreach (FileInfo file in files) + { + streams.Add(file.OpenRead()); + } + + Stream mergedStream = MergeExcelDocuments(streams); + + FileStream fileStream = new FileStream(outputPath + "MergedExcel.xlsx", FileMode.Create, FileAccess.Write); + mergedStream.Position = 0; + mergedStream.CopyTo(fileStream); + fileStream.Close(); + } + + /// + /// Merge Excel documents from the list of Excel streams + /// + /// List of Excel document stream to be merged + /// + public static Stream MergeExcelDocuments(List streams) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(0); + + //Loop through each Excel document and add the worksheets to the new workbook + foreach (Stream stream in streams) + { + stream.Position = 0; + IWorkbook tempWorkbook = application.Workbooks.Open(stream); + workbook.Worksheets.AddCopy(tempWorkbook.Worksheets); + tempWorkbook.Close(); + } + + //Save the workbook to a memory stream + MemoryStream memoryStream = new MemoryStream(); + workbook.Version = ExcelVersion.Xlsx; + workbook.SaveAs(memoryStream); + + return memoryStream; + } + } + } +} + + + + + + + diff --git a/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/README.md b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/README.md new file mode 100644 index 00000000..25b4c25c --- /dev/null +++ b/Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/README.md @@ -0,0 +1,42 @@ +# Merge Multiple Excel Files into One Excel File in C# + +The [.NET Excel Library](https://www.syncfusion.com/document-sdk/net-excel-library) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can **merge multiple Excel files into one Excel file** using C#. + +## Steps to Merge Multiple Excel Files into One Excel File + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. +```csharp +using System.IO; +using Syncfusion.XlsIO; +``` +Step 5: Include the below code snippet in **Program.cs** to merge multiple Excel files into one Excel file +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(0); + + //Loop through each Excel document and add the worksheets to the new workbook + foreach (Stream stream in streams) + { + stream.Position = 0; + IWorkbook tempWorkbook = application.Workbooks.Open(stream); + workbook.Worksheets.AddCopy(tempWorkbook.Worksheets); + tempWorkbook.Close(); + } + + //Save the workbook to a memory stream + MemoryStream memoryStream = new MemoryStream(); + workbook.Version = ExcelVersion.Xlsx; + workbook.SaveAs(memoryStream); + + return memoryStream; +} +``` \ No newline at end of file diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument.sln b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument.sln new file mode 100644 index 00000000..4b36f583 --- /dev/null +++ b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34310.174 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SplitExcelDocument", "SplitExcelDocument\SplitExcelDocument.csproj", "{F84710FF-A205-4540-8A1F-8C05813225DD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F84710FF-A205-4540-8A1F-8C05813225DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F84710FF-A205-4540-8A1F-8C05813225DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F84710FF-A205-4540-8A1F-8C05813225DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F84710FF-A205-4540-8A1F-8C05813225DD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6FCE571C-9967-4868-B912-EC01287A7610} + EndGlobalSection +EndGlobal diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Data/Report.xlsx b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Data/Report.xlsx new file mode 100644 index 00000000..b312aada Binary files /dev/null and b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Data/Report.xlsx differ diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/.gitkeep b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Budget.xlsx b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Budget.xlsx new file mode 100644 index 00000000..9833d6db Binary files /dev/null and b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Budget.xlsx differ diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Data.xlsx b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Data.xlsx new file mode 100644 index 00000000..98eb2f7b Binary files /dev/null and b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Data.xlsx differ diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Employee Details.xlsx b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Employee Details.xlsx new file mode 100644 index 00000000..0f0554c2 Binary files /dev/null and b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Output/Employee Details.xlsx differ diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Program.cs b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Program.cs new file mode 100644 index 00000000..d8c58d7a --- /dev/null +++ b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/Program.cs @@ -0,0 +1,54 @@ +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); + } + /// + /// Split the Excel document from the given path + /// + /// Excel file path + 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(); + } + } + } + } +} + + + + + + diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/README.md b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/README.md new file mode 100644 index 00000000..c7a4b0f4 --- /dev/null +++ b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/README.md @@ -0,0 +1,40 @@ +# Split an Excel File into Multiple Excel Files in C# + +The [.NET Excel Library](https://www.syncfusion.com/document-sdk/net-excel-library) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can **split an Excel file into multiple Excel files** using C#. + +## Steps to Split an Excel File into Multiple Excel Files + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. +```csharp +using System.IO; +using Syncfusion.XlsIO; +``` +Step 5: Include the below code snippet in **Program.cs** to split an Excel file into multiple Excel files +```csharp +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(); + } +} +``` \ No newline at end of file diff --git a/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/SplitExcelDocument.csproj b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/SplitExcelDocument.csproj new file mode 100644 index 00000000..673cebc1 --- /dev/null +++ b/Real Time Examples in Excel/SplitExcelDocument/.NET/SplitExcelDocument/SplitExcelDocument/SplitExcelDocument.csproj @@ -0,0 +1,34 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + Always + + + Always + + + + + + + + + + + diff --git a/Real Time Examples in Excel/SplitExcelDocument/SplitExcelDocument/README.md b/Real Time Examples in Excel/SplitExcelDocument/SplitExcelDocument/README.md new file mode 100644 index 00000000..c7a4b0f4 --- /dev/null +++ b/Real Time Examples in Excel/SplitExcelDocument/SplitExcelDocument/README.md @@ -0,0 +1,40 @@ +# Split an Excel File into Multiple Excel Files in C# + +The [.NET Excel Library](https://www.syncfusion.com/document-sdk/net-excel-library) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can **split an Excel file into multiple Excel files** using C#. + +## Steps to Split an Excel File into Multiple Excel Files + +Step 1: Create a new C# Console Application project. + +Step 2: Name the project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. +```csharp +using System.IO; +using Syncfusion.XlsIO; +``` +Step 5: Include the below code snippet in **Program.cs** to split an Excel file into multiple Excel files +```csharp +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(); + } +} +``` \ No newline at end of file