diff --git a/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart.sln b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart.sln new file mode 100644 index 00000000..e59754d2 --- /dev/null +++ b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35506.116 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +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}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {750866FE-E7C6-4635-BA18-ABA4C6CA96E4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Add oval shape to chart.csproj b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Add oval shape to chart.csproj new file mode 100644 index 00000000..4fbceecd --- /dev/null +++ b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Add oval shape to chart.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Add_oval_shape_to_chart + enable + enable + + + + + + + + + Always + + + + diff --git a/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Output/.gitkeep b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Program.cs b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Program.cs new file mode 100644 index 00000000..e1e1298f --- /dev/null +++ b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/Add oval shape to chart/Program.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using Syncfusion.Drawing; +using Syncfusion.XlsIO; + +namespace Add_Oval_Shape_Chart +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Add chart to worksheet + IChart chart = worksheet.Charts.Add(); + + //Add oval shape to chart + IShape shape = chart.Shapes.AddAutoShapes(AutoShapeType.Oval, 20, 60, 500, 400); + + //Format the shape + shape.Line.ForeColorIndex = ExcelKnownColors.Red; + + //Add the text to the oval shape and set the text alignment on the shape + shape.TextFrame.TextRange.Text = "This is an oval shape"; + shape.TextFrame.VerticalAlignment = ExcelVerticalAlignment.MiddleCentered; + shape.TextFrame.HorizontalAlignment = ExcelHorizontalAlignment.CenterMiddle; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + } + } +} diff --git a/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/README.md b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/README.md new file mode 100644 index 00000000..afca25b7 --- /dev/null +++ b/FAQ/Add oval shape to chart/.NET/Add oval shape to chart/README.md @@ -0,0 +1,52 @@ +# How to add Oval shape to Excel chart using XlsIO? + +Step 1: Create a New C# Console Application Project. + +Step 2: Name the Project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. + +```csharp +using System; +using System.IO; +using Syncfusion.Drawing; +using Syncfusion.XlsIO; +``` + +Step 5: Include the below code snippet in **Program.cs** to add Oval shape to Excel chart using XlsIO. + +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Add chart to worksheet + IChart chart = worksheet.Charts.Add(); + + //Add oval shape to chart + IShape shape = chart.Shapes.AddAutoShapes(AutoShapeType.Oval, 20, 60, 500, 400); + + //Format the shape + shape.Line.ForeColorIndex = ExcelKnownColors.Red; + + //Add the text to the oval shape and set the text alignment on the shape + shape.TextFrame.TextRange.Text = "This is an oval shape"; + shape.TextFrame.VerticalAlignment = ExcelVerticalAlignment.MiddleCentered; + shape.TextFrame.HorizontalAlignment = ExcelHorizontalAlignment.CenterMiddle; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); +} +``` +