Skip to content

Commit 37cd66b

Browse files
Added examples to export data to Excel template in C#.
1 parent 7bdcab1 commit 37cd66b

File tree

177 files changed

+3832
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+3832
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
5+
</startup>
6+
</configuration>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using Syncfusion.XlsIO;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
5+
namespace TemplateMarker
6+
{
7+
class Employee
8+
{
9+
private string m_name;
10+
private int m_id;
11+
private int m_age;
12+
13+
public string Name
14+
{
15+
get
16+
{
17+
return m_name;
18+
}
19+
20+
set
21+
{
22+
m_name = value;
23+
}
24+
}
25+
public int Id
26+
{
27+
get
28+
{
29+
return m_id;
30+
}
31+
32+
set
33+
{
34+
m_id = value;
35+
}
36+
}
37+
public int Age
38+
{
39+
get
40+
{
41+
return m_age;
42+
}
43+
44+
set
45+
{
46+
m_age = value;
47+
}
48+
}
49+
}
50+
51+
class Program
52+
{
53+
public static List<Employee> GetEmployeeDetails()
54+
{
55+
List<Employee> employeeList = new List<Employee>();
56+
Employee emp = new Employee();
57+
emp.Name = "Andy Bernard";
58+
emp.Id = 1011;
59+
emp.Age = 35;
60+
61+
employeeList.Add(emp);
62+
63+
emp = new Employee();
64+
emp.Name = "Jim Halpert";
65+
emp.Id = 1012;
66+
emp.Age = 26;
67+
68+
employeeList.Add(emp);
69+
70+
emp = new Employee();
71+
emp.Name = "Karen Fillippelli";
72+
emp.Id = 1013;
73+
emp.Age = 28;
74+
75+
employeeList.Add(emp);
76+
77+
return employeeList;
78+
}
79+
80+
public static void Main(string[] args)
81+
{
82+
//Instantiate the spreadsheet creation engine
83+
using (ExcelEngine excelEngine = new ExcelEngine())
84+
{
85+
IApplication application = excelEngine.Excel;
86+
IWorkbook workbook = application.Workbooks.Create(1);
87+
IWorksheet worksheet = workbook.Worksheets[0];
88+
89+
//Adding header text
90+
worksheet["A1"].Text = "\"Horizontal\" Argument";
91+
worksheet["A3"].Text = "Name";
92+
worksheet["A4"].Text = "Id";
93+
worksheet["A5"].Text = "Age";
94+
worksheet["A3:A5"].CellStyle.Font.Bold = true;
95+
96+
//Adding markers dynamically with the argument, 'horizontal'
97+
worksheet["B3"].Text = "%Employee.Name;horizontal";
98+
worksheet["B4"].Text = "%Employee.Id;horizontal";
99+
worksheet["B5"].Text = "%Employee.Age;horizontal";
100+
101+
workbook.SaveAs("Template.xlsx");
102+
103+
//Create template marker processor
104+
ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor();
105+
106+
//Add marker variable
107+
marker.AddVariable("Employee", GetEmployeeDetails());
108+
109+
//Apply markers
110+
marker.ApplyMarkers();
111+
112+
//Save and close the workbook
113+
Stream stream = File.Create("Output.xlsx");
114+
worksheet.UsedRange.AutofitColumns();
115+
workbook.SaveAs(stream);
116+
}
117+
}
118+
}
119+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("TemplateMarker")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("TemplateMarker")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("a6c5ab04-f00e-4593-b57a-28e0d41efb9f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{A6C5AB04-F00E-4593-B57A-28E0D41EFB9F}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>TemplateMarker</RootNamespace>
11+
<AssemblyName>TemplateMarker</AssemblyName>
12+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Syncfusion.Compression.Base, Version=18.1460.0.53, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
37+
<HintPath>packages\Syncfusion.Compression.Base.18.1.0.53\lib\net46\Syncfusion.Compression.Base.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Syncfusion.Licensing, Version=18.1460.0.53, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
40+
<HintPath>packages\Syncfusion.Licensing.18.1.0.53\lib\net46\Syncfusion.Licensing.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Syncfusion.XlsIO.Base, Version=18.1460.0.53, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
43+
<HintPath>packages\Syncfusion.XlsIO.WinForms.18.1.0.53\lib\net46\Syncfusion.XlsIO.Base.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Xml.Linq" />
48+
<Reference Include="System.Data.DataSetExtensions" />
49+
<Reference Include="Microsoft.CSharp" />
50+
<Reference Include="System.Data" />
51+
<Reference Include="System.Net.Http" />
52+
<Reference Include="System.Xml" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Compile Include="Program.cs" />
56+
<Compile Include="Properties\AssemblyInfo.cs" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<None Include="App.config" />
60+
<None Include="packages.config" />
61+
</ItemGroup>
62+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
64+
Other similar extension points exist, see Microsoft.Common.targets.
65+
<Target Name="BeforeBuild">
66+
</Target>
67+
<Target Name="AfterBuild">
68+
</Target>
69+
-->
70+
</Project>
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 16
4+
VisualStudioVersion = 16.0.30105.148
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemplateMarker-Horizontal-Argument", "TemplateMarker-Horizontal-Argument.csproj", "{A6C5AB04-F00E-4593-B57A-28E0D41EFB9F}"
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+
{A6C5AB04-F00E-4593-B57A-28E0D41EFB9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A6C5AB04-F00E-4593-B57A-28E0D41EFB9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A6C5AB04-F00E-4593-B57A-28E0D41EFB9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A6C5AB04-F00E-4593-B57A-28E0D41EFB9F}.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 = {E8586048-A416-4CA9-8607-8D46F9E2847B}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Syncfusion.Compression.Base" version="18.1.0.53" targetFramework="net46" />
4+
<package id="Syncfusion.Licensing" version="18.1.0.53" targetFramework="net46" />
5+
<package id="Syncfusion.XlsIO.WinForms" version="18.1.0.53" targetFramework="net46" />
6+
</packages>
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
5+
</startup>
6+
</configuration>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using Syncfusion.XlsIO;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
5+
namespace TemplateMarker
6+
{
7+
class Employee
8+
{
9+
private string m_name;
10+
private int m_id;
11+
private int m_age;
12+
13+
public string Name
14+
{
15+
get
16+
{
17+
return m_name;
18+
}
19+
20+
set
21+
{
22+
m_name = value;
23+
}
24+
}
25+
public int Id
26+
{
27+
get
28+
{
29+
return m_id;
30+
}
31+
32+
set
33+
{
34+
m_id = value;
35+
}
36+
}
37+
public int Age
38+
{
39+
get
40+
{
41+
return m_age;
42+
}
43+
44+
set
45+
{
46+
m_age = value;
47+
}
48+
}
49+
}
50+
51+
class Program
52+
{
53+
public static List<Employee> GetEmployeeDetails()
54+
{
55+
List<Employee> employeeList = new List<Employee>();
56+
Employee emp = new Employee();
57+
emp.Name = "Andy Bernard";
58+
emp.Id = 1011;
59+
emp.Age = 35;
60+
61+
employeeList.Add(emp);
62+
63+
emp = new Employee();
64+
emp.Name = "Jim Halpert";
65+
emp.Id = 1012;
66+
emp.Age = 26;
67+
68+
employeeList.Add(emp);
69+
70+
emp = new Employee();
71+
emp.Name = "Karen Fillippelli";
72+
emp.Id = 1013;
73+
emp.Age = 28;
74+
75+
employeeList.Add(emp);
76+
77+
return employeeList;
78+
}
79+
80+
public static void Main(string[] args)
81+
{
82+
//Instantiate the spreadsheet creation engine
83+
using (ExcelEngine excelEngine = new ExcelEngine())
84+
{
85+
IApplication application = excelEngine.Excel;
86+
IWorkbook workbook = application.Workbooks.Create(1);
87+
IWorksheet worksheet = workbook.Worksheets[0];
88+
89+
//Adding header text
90+
worksheet["A1"].Text = "\"Jump\" Argument";
91+
92+
worksheet["A3"].Text = "Name";
93+
worksheet["B3"].Text = "Id";
94+
worksheet["C3"].Text = "Age";
95+
96+
worksheet["A3:C3"].CellStyle.Font.Bold = true;
97+
98+
//Adding markers dynamically with the argument, 'Jump'
99+
worksheet["A4"].Text = "%Employee.Name;jump:R[2]C";
100+
worksheet["B4"].Text = "%Employee.Id;jump:R[2]C";
101+
worksheet["C4"].Text = "%Employee.Age;jump:R[2]C";
102+
103+
//Create template marker processor
104+
ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor();
105+
106+
//Add marker variable
107+
marker.AddVariable("Employee", GetEmployeeDetails());
108+
109+
//Apply markers
110+
marker.ApplyMarkers();
111+
112+
//Save and close the workbook
113+
Stream stream = File.Create("Output.xlsx");
114+
worksheet.UsedRange.AutofitColumns();
115+
workbook.SaveAs(stream);
116+
}
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)