Skip to content

Commit a386662

Browse files
authored
Merge pull request #166 from SyncfusionExamples/942643-BarcodeExample
942643-FAQ for How to add Barcode in Excel document using C#-Example
2 parents 10c51cf + 867791f commit a386662

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-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}") = "Barcode", "Barcode\Barcode.csproj", "{97F53687-3D4D-419F-8A16-D6C24345A2FD}"
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+
{97F53687-3D4D-419F-8A16-D6C24345A2FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{97F53687-3D4D-419F-8A16-D6C24345A2FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{97F53687-3D4D-419F-8A16-D6C24345A2FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{97F53687-3D4D-419F-8A16-D6C24345A2FD}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
<None Update="Output\*">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
20+
</Project>
64.7 KB
Loading
21 KB
Loading

FAQ/Barcode/.NET/Add Barcode/Barcode/Output/.gitkeep

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
5+
namespace AddBarcode
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+
IWorkbook workbook = application.Workbooks.Create(1);
16+
IWorksheet worksheet = workbook.Worksheets[0];
17+
18+
// Load barcodes from local files
19+
FileStream barcode1 = new FileStream("Data/Barcode1.png", FileMode.Open, FileAccess.Read);
20+
FileStream barcode2 = new FileStream("Data/Barcode2.png", FileMode.Open, FileAccess.Read);
21+
worksheet.Pictures.AddPicture(1, 1, barcode1);
22+
worksheet.Pictures.AddPicture(15, 1, barcode2);
23+
worksheet.Pictures.AddPicture(1, 10, barcode1);
24+
worksheet.Pictures.AddPicture(15, 10, barcode2);
25+
26+
// Save to file system
27+
FileStream stream = new FileStream("Output/Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
28+
workbook.SaveAs(stream);
29+
workbook.Close();
30+
excelEngine.Dispose();
31+
}
32+
33+
}
34+
35+
}
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# How to add Barcode in 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 add Barcode in Excel document.
18+
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(1);
25+
IWorksheet worksheet = workbook.Worksheets[0];
26+
27+
// Load barcodes from local files
28+
FileStream barcode1 = new FileStream("Data/Barcode1.png", FileMode.Open, FileAccess.Read);
29+
FileStream barcode2 = new FileStream("Data/Barcode2.png", FileMode.Open, FileAccess.Read);
30+
worksheet.Pictures.AddPicture(1, 1, barcode1);
31+
worksheet.Pictures.AddPicture(15, 1, barcode2);
32+
worksheet.Pictures.AddPicture(1, 10, barcode1);
33+
worksheet.Pictures.AddPicture(15, 10, barcode2);
34+
35+
// Save to file system
36+
FileStream stream = new FileStream("Output/Output.xlsx", FileMode.OpenOrCreate, FileAccess.ReadWrite);
37+
workbook.SaveAs(stream);
38+
workbook.Close();
39+
excelEngine.Dispose();
40+
}
41+
```
42+

0 commit comments

Comments
 (0)