diff --git a/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart.sln b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart.sln new file mode 100644 index 00000000..2b6c36d1 --- /dev/null +++ b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position 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}") = "Position Chart", "Position Chart\Position Chart.csproj", "{8E50C960-D43F-4F91-903D-5F818E7C4C7B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8E50C960-D43F-4F91-903D-5F818E7C4C7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E50C960-D43F-4F91-903D-5F818E7C4C7B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E50C960-D43F-4F91-903D-5F818E7C4C7B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E50C960-D43F-4F91-903D-5F818E7C4C7B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Output/.gitkeep b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Position Chart.csproj b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Position Chart.csproj new file mode 100644 index 00000000..e5ab3a69 --- /dev/null +++ b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Position Chart.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Position_Chart + enable + enable + + + + + + + + + Always + + + + diff --git a/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Program.cs b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Program.cs new file mode 100644 index 00000000..91b747e4 --- /dev/null +++ b/Create and Edit Charts/Position Chart/.NET/Position Chart/Position Chart/Program.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using Syncfusion.XlsIO; + +namespace Position_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 data + worksheet.Range["A1"].Text = "Category"; + worksheet.Range["B1"].Text = "Value"; + worksheet.Range["A2"].Text = "A"; + worksheet.Range["A3"].Text = "B"; + worksheet.Range["A4"].Text = "C"; + worksheet.Range["B2"].Number = 10; + worksheet.Range["B3"].Number = 20; + worksheet.Range["B4"].Number = 30; + + //Add a chart + IChartShape chart = worksheet.Charts.Add(); + chart.DataRange = worksheet.Range["A1:B4"]; + chart.ChartType = ExcelChartType.Column_Clustered; + + //Set chart position + chart.Top = 100; + chart.Left = 150; + + //Set height and width + IChart chart1 = worksheet.Charts[0]; + chart1.Height = 300; + chart1.Width = 500; + + #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(); + } + } + } +} \ No newline at end of file diff --git a/Create and Edit Charts/Position Chart/.NET/Position Chart/README.md b/Create and Edit Charts/Position Chart/.NET/Position Chart/README.md new file mode 100644 index 00000000..14677da9 --- /dev/null +++ b/Create and Edit Charts/Position Chart/.NET/Position Chart/README.md @@ -0,0 +1,60 @@ +# Positioning a Chart + +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.XlsIO; +``` + +Step 5: Include the below code snippet in **Program.cs** to position a chart in Excel. + +```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 data + worksheet.Range["A1"].Text = "Category"; + worksheet.Range["B1"].Text = "Value"; + worksheet.Range["A2"].Text = "A"; + worksheet.Range["A3"].Text = "B"; + worksheet.Range["A4"].Text = "C"; + worksheet.Range["B2"].Number = 10; + worksheet.Range["B3"].Number = 20; + worksheet.Range["B4"].Number = 30; + + //Add a chart + IChartShape chart = worksheet.Charts.Add(); + chart.DataRange = worksheet.Range["A1:B4"]; + chart.ChartType = ExcelChartType.Column_Clustered; + + //Set chart position + chart.Top = 100; + chart.Left = 150; + + //Set height and width + IChart chart1 = worksheet.Charts[0]; + chart1.Height = 300; + chart1.Width = 500; + + #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(); +} +``` \ No newline at end of file