Skip to content

Commit 74f0abd

Browse files
committed
975271---Sparklines-Usecase
1 parent e801c09 commit 74f0abd

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
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.14.36109.1 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SalesTrendWithSparklines", "SalesTrendWithSparklines\SalesTrendWithSparklines.csproj", "{65DA17F0-EE05-41AC-B641-277B8ADDC9A6}"
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+
{65DA17F0-EE05-41AC-B641-277B8ADDC9A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{65DA17F0-EE05-41AC-B641-277B8ADDC9A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{65DA17F0-EE05-41AC-B641-277B8ADDC9A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{65DA17F0-EE05-41AC-B641-277B8ADDC9A6}.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 = {028FC0D5-08B9-4204-8E36-62B25FAD4F06}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+

2+
using Syncfusion.XlsIO;
3+
using Syncfusion.Drawing;
4+
using System.IO;
5+
6+
class SalesTrendWithSparklines
7+
{
8+
static void Main()
9+
{
10+
using (ExcelEngine excelEngine = new ExcelEngine())
11+
{
12+
IApplication application = excelEngine.Excel;
13+
application.DefaultVersion = ExcelVersion.Xlsx;
14+
15+
// Load the Excel file with sales data
16+
FileStream inputStream = new FileStream("../../../Data/Sales Data.xlsx", FileMode.Open, FileAccess.Read);
17+
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
IWorksheet sheet = workbook.Worksheets[0];
20+
21+
sheet["G1"].Text = "Sales Trend";
22+
sheet["G1"].CellStyle.Font.Bold = true;
23+
24+
// Create a Sparkline Group
25+
ISparklineGroup sparklineGroup = sheet.SparklineGroups.Add();
26+
27+
// Add a Line Sparkline to the group
28+
ISparklines sparklines = sparklineGroup.Add();
29+
30+
// Define the data range and reference range for the sparkline
31+
IRange dataRange = sheet.Range["B2:F26"];
32+
IRange referenceRange = sheet.Range["G2:G26"];
33+
sparklines.Add(dataRange, referenceRange);
34+
35+
// Set the sparkline type to Line
36+
sparklineGroup.SparklineType = SparklineType.Line;
37+
38+
// Customizing Line Sparkline
39+
sparklineGroup.LineWeight = 1;
40+
sparklineGroup.ShowMarkers = true;
41+
42+
//Set sparkline line color
43+
sparklineGroup.SparklineColor = Color.Orange;
44+
45+
// Set the high and low point colors
46+
sparklineGroup.HighPointColor = Color.Red;
47+
sparklineGroup.LowPointColor = Color.Green;
48+
49+
//Customizing markers
50+
sparklineGroup.MarkersColor = Color.Blue;
51+
52+
// Save the Excel file
53+
using (FileStream stream = new FileStream("SalesDataTrend.xlsx", FileMode.Create, FileAccess.Write))
54+
{
55+
workbook.SaveAs(stream);
56+
}
57+
}
58+
}
59+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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="30.2.4" />
12+
</ItemGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)