Skip to content

Commit 3fa836a

Browse files
935073-OverrideExcelExample
1 parent 5d30f95 commit 3fa836a

File tree

6 files changed

+126
-0
lines changed

6 files changed

+126
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Override Excel Document", "Override Excel Document\Override Excel Document.csproj", "{35FB85A6-D490-446B-8D9F-E906A57C19DE}"
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+
{35FB85A6-D490-446B-8D9F-E906A57C19DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{35FB85A6-D490-446B-8D9F-E906A57C19DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{35FB85A6-D490-446B-8D9F-E906A57C19DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{35FB85A6-D490-446B-8D9F-E906A57C19DE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Binary file not shown.

FAQ/Override Excel Document/.NET/Override Excel Document/Override Excel Document/Output/.gitkeep

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Override_Excel_Document</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Output\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
5+
namespace Override_Excel_Document
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
using (ExcelEngine excelEngine = new ExcelEngine())
12+
{
13+
IApplication application = excelEngine.Excel;
14+
application.DefaultVersion = ExcelVersion.Xlsx;
15+
16+
//Open an existing Excel file as stream
17+
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read);
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
IWorksheet worksheet = workbook.Worksheets[0];
20+
21+
//Modify the data
22+
worksheet.Range["A1"].Text = "Hello World";
23+
24+
//Dispose input stream
25+
inputStream.Dispose();
26+
27+
#region Save
28+
//Saving the workbook
29+
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.xlsx"), FileMode.Create, FileAccess.Write);
30+
workbook.SaveAs(outputStream);
31+
#endregion
32+
33+
//Dispose output stream
34+
outputStream.Dispose();
35+
}
36+
}
37+
}
38+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# How to override an Excel document using C#?
2+
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
6+
7+
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).
8+
9+
Step 4: Include the following namespaces in the **Program.cs** file.
10+
11+
```csharp
12+
using System;
13+
using System.IO;
14+
using Syncfusion.XlsIO;
15+
```
16+
17+
Step 5: Include the below code snippet in **Program.cs** to override an Excel document.
18+
19+
```csharp
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
IApplication application = excelEngine.Excel;
23+
application.DefaultVersion = ExcelVersion.Xlsx;
24+
25+
//Open an existing Excel file as stream
26+
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sample.xlsx"), FileMode.Open, FileAccess.Read);
27+
IWorkbook workbook = application.Workbooks.Open(inputStream);
28+
IWorksheet worksheet = workbook.Worksheets[0];
29+
30+
//Modify the data
31+
worksheet.Range["A1"].Text = "Hello World";
32+
33+
//Dispose input stream
34+
inputStream.Dispose();
35+
36+
#region Save
37+
//Saving the workbook
38+
FileStream outputStream = new FileStream(Path.GetFullPath("Output/Sample.xlsx"), FileMode.Create, FileAccess.Write);
39+
workbook.SaveAs(outputStream);
40+
#endregion
41+
42+
//Dispose output stream
43+
outputStream.Dispose();
44+
}
45+
```

0 commit comments

Comments
 (0)