Skip to content

Commit ae35238

Browse files
authored
Merge pull request #183 from SyncfusionExamples/261762-AddOvalShapeExample
261762-How to add Oval shape to Excel chart using XlsIO?
2 parents ce1e9fd + 83ab0db commit ae35238

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-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}") = "Add oval shape to chart", "Add oval shape to chart\Add oval shape to chart.csproj", "{750866FE-E7C6-4635-BA18-ABA4C6CA96E4}"
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+
{750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
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>Add_oval_shape_to_chart</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>

FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Output/.gitkeep

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.Drawing;
4+
using Syncfusion.XlsIO;
5+
6+
namespace Add_Oval_Shape_Chart
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
using (ExcelEngine excelEngine = new ExcelEngine())
13+
{
14+
IApplication application = excelEngine.Excel;
15+
application.DefaultVersion = ExcelVersion.Xlsx;
16+
IWorkbook workbook = application.Workbooks.Create(1);
17+
IWorksheet worksheet = workbook.Worksheets[0];
18+
19+
//Add chart to worksheet
20+
IChart chart = worksheet.Charts.Add();
21+
22+
//Add oval shape to chart
23+
IShape shape = chart.Shapes.AddAutoShapes(AutoShapeType.Oval, 20, 60, 500, 400);
24+
25+
//Format the shape
26+
shape.Line.ForeColorIndex = ExcelKnownColors.Red;
27+
28+
//Add the text to the oval shape and set the text alignment on the shape
29+
shape.TextFrame.TextRange.Text = "This is an oval shape";
30+
shape.TextFrame.VerticalAlignment = ExcelVerticalAlignment.MiddleCentered;
31+
shape.TextFrame.HorizontalAlignment = ExcelHorizontalAlignment.CenterMiddle;
32+
33+
#region Save
34+
//Saving the workbook
35+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
36+
workbook.SaveAs(outputStream);
37+
#endregion
38+
39+
//Dispose streams
40+
outputStream.Dispose();
41+
}
42+
}
43+
}
44+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# How to add Oval shape to Excel chart using XlsIO?
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.Drawing;
15+
using Syncfusion.XlsIO;
16+
```
17+
18+
Step 5: Include the below code snippet in **Program.cs** to add Oval shape to Excel chart using XlsIO.
19+
20+
```csharp
21+
using (ExcelEngine excelEngine = new ExcelEngine())
22+
{
23+
IApplication application = excelEngine.Excel;
24+
application.DefaultVersion = ExcelVersion.Xlsx;
25+
IWorkbook workbook = application.Workbooks.Create(1);
26+
IWorksheet worksheet = workbook.Worksheets[0];
27+
28+
//Add chart to worksheet
29+
IChart chart = worksheet.Charts.Add();
30+
31+
//Add oval shape to chart
32+
IShape shape = chart.Shapes.AddAutoShapes(AutoShapeType.Oval, 20, 60, 500, 400);
33+
34+
//Format the shape
35+
shape.Line.ForeColorIndex = ExcelKnownColors.Red;
36+
37+
//Add the text to the oval shape and set the text alignment on the shape
38+
shape.TextFrame.TextRange.Text = "This is an oval shape";
39+
shape.TextFrame.VerticalAlignment = ExcelVerticalAlignment.MiddleCentered;
40+
shape.TextFrame.HorizontalAlignment = ExcelHorizontalAlignment.CenterMiddle;
41+
42+
#region Save
43+
//Saving the workbook
44+
FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write);
45+
workbook.SaveAs(outputStream);
46+
#endregion
47+
48+
//Dispose streams
49+
outputStream.Dispose();
50+
}
51+
```
52+

0 commit comments

Comments
 (0)