Skip to content

Commit ec3ef03

Browse files
authored
Merge pull request #346 from SyncfusionExamples/1046485-AddReadMe
Task(1046485)-Added ReadMe files and modified folder structures
2 parents 7bf7784 + 0796175 commit ec3ef03

22 files changed

Lines changed: 483 additions & 0 deletions

File tree

Editing Excel cells/Replace/.NET/Replace/README.md renamed to Editing Excel cells/Replace/.NET/Replace/Replace/README.md

File renamed without changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Edit Excel document using C#
2+
3+
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.
4+
5+
## Steps to edit an Excel document programmatically
6+
7+
Step 1: Create a new C# Console Application project.
8+
9+
Step 2: Name the project.
10+
11+
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).
12+
13+
Step 4: Include the following namespaces in the **Program.cs** file.
14+
```csharp
15+
using System.IO;
16+
using Syncfusion.XlsIO;
17+
```
18+
Step 5: Include the below code snippet in **Program.cs** to edit an Excel document.
19+
```csharp
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
IApplication application = excelEngine.Excel;
23+
application.DefaultVersion = ExcelVersion.Xlsx;
24+
25+
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx"));
26+
IWorksheet sheet = workbook.Worksheets[0];
27+
28+
sheet.Range["D1"].Text = "In Stock";
29+
sheet.Range["E1"].Text = "Total Price";
30+
sheet.Range["F1"].Text = "Discount (10%)";
31+
sheet.Range["G1"].Text = "Final Price";
32+
33+
sheet.Range["D2"].Boolean = true;
34+
sheet.Range["D3"].Boolean = true;
35+
36+
sheet.Range["A4"].Text = "Bag";
37+
sheet.Range["B4"].Number = 500;
38+
sheet.Range["C4"].Number = 5;
39+
sheet.Range["D4"].Boolean = false;
40+
41+
sheet.Range["A5"].Text = "Bottle";
42+
sheet.Range["B5"].Number = 100;
43+
sheet.Range["C5"].Number = 10;
44+
sheet.Range["D5"].Boolean = true;
45+
46+
sheet.Range["E2"].Formula = "B2*C2";
47+
sheet.Range["F2"].Formula = "E2*0.1";
48+
sheet.Range["G2"].Formula = "E2-F2";
49+
50+
sheet.Range["E3"].Formula = "B3*C3";
51+
sheet.Range["F3"].Formula = "E3*0.1";
52+
sheet.Range["G3"].Formula = "E3-F3";
53+
54+
sheet.Range["E4"].Formula = "B4*C4";
55+
sheet.Range["F4"].Formula = "E4*0.1";
56+
sheet.Range["G4"].Formula = "E4-F4";
57+
58+
sheet.Range["E5"].Formula = "B5*C5";
59+
sheet.Range["F5"].Formula = "E5*0.1";
60+
sheet.Range["G5"].Formula = "E5-F5";
61+
62+
sheet.Range["A6"].Text = "Totals";
63+
sheet.Range["E6"].Formula = "SUM(E2:E5)";
64+
sheet.Range["F6"].Formula = "SUM(F2:F5)";
65+
sheet.Range["G6"].Formula = "SUM(G2:G5)";
66+
67+
sheet.Range["A1:G1"].CellStyle.Font.Bold = true;
68+
sheet.Range["A1:G6"].CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
69+
70+
IListObject table = sheet.ListObjects.Create("SalesTable", sheet.Range["A1:G6"]);
71+
table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium23;
72+
73+
workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx"));
74+
workbook.Close();
75+
}
76+
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Merge Multiple Excel Files into One Excel File in C#
2+
3+
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#.
4+
5+
## Steps to Merge Multiple Excel Files into One Excel File
6+
7+
Step 1: Create a new C# Console Application project.
8+
9+
Step 2: Name the project.
10+
11+
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).
12+
13+
Step 4: Include the following namespaces in the **Program.cs** file.
14+
```csharp
15+
using System.IO;
16+
using Syncfusion.XlsIO;
17+
```
18+
Step 5: Include the below code snippet in **Program.cs** to merge multiple Excel files into one Excel file
19+
```csharp
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
IApplication application = excelEngine.Excel;
23+
application.DefaultVersion = ExcelVersion.Xlsx;
24+
IWorkbook workbook = application.Workbooks.Create(0);
25+
26+
//Loop through each Excel document and add the worksheets to the new workbook
27+
foreach (Stream stream in streams)
28+
{
29+
stream.Position = 0;
30+
IWorkbook tempWorkbook = application.Workbooks.Open(stream);
31+
workbook.Worksheets.AddCopy(tempWorkbook.Worksheets);
32+
tempWorkbook.Close();
33+
}
34+
35+
//Save the workbook to a memory stream
36+
MemoryStream memoryStream = new MemoryStream();
37+
workbook.Version = ExcelVersion.Xlsx;
38+
workbook.SaveAs(memoryStream);
39+
40+
return memoryStream;
41+
}
42+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34310.174
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MergeExcel", "MergeExcel\MergeExcel.csproj", "{B68720C9-71D9-4706-B1E2-7C207699EF1D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B68720C9-71D9-4706-B1E2-7C207699EF1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B68720C9-71D9-4706-B1E2-7C207699EF1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B68720C9-71D9-4706-B1E2-7C207699EF1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B68720C9-71D9-4706-B1E2-7C207699EF1D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C8553F0E-B638-4BC4-9E5B-2FC2C818FB4A}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Folder Include="Data\" />
16+
<Folder Include="Output\" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<None Update="Data\*">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
23+
<None Update="Output\*">
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
</None>
26+
</ItemGroup>
27+
28+
</Project>
29+
30+
31+
32+
33+
34+
35+

Real Time Examples in Excel/Merge Excel Documents/.NET/MergeExcel/MergeExcel/Output/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)