|
| 1 | +--- |
| 2 | +title: Retrieve the name of the chart in an Excel worksheet | Syncfusion |
| 3 | +description: Code example to retrieve the name of the chart in an Excel worksheet using Syncfusion .NET Excel library (XlsIO). |
| 4 | +platform: document-processing |
| 5 | +control: XlsIO |
| 6 | +documentation: UG |
| 7 | +--- |
| 8 | + |
| 9 | +# How to retrieve the name of the chart in an Excel worksheet? |
| 10 | + |
| 11 | +The following code examples demonstrate retrieving the name of the chart in an Excel worksheet using C# (Cross-platform and Windows-specific) and VB.NET. |
| 12 | + |
| 13 | +{% tabs %} |
| 14 | +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Chart/.NET/ChartNameInWorksheet/ChartNameInWorksheet/Program.cs,180" %} |
| 15 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 16 | +{ |
| 17 | + IApplication application = excelEngine.Excel; |
| 18 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 19 | + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); |
| 20 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 21 | + |
| 22 | + //Get the chart name |
| 23 | + string chartName = worksheet.Charts[0].Name; |
| 24 | + //Display the chart name |
| 25 | + Console.WriteLine("The name of the chart is: " + chartName); |
| 26 | + |
| 27 | + //Saving the workbook |
| 28 | + workbook.SaveAs(Path.GetFullPath(@"Output/Output.xlsx")); |
| 29 | +} |
| 30 | +{% endhighlight %} |
| 31 | + |
| 32 | +{% highlight c# tabtitle="C# [Windows-specific]" %} |
| 33 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 34 | +{ |
| 35 | + IApplication application = excelEngine.Excel; |
| 36 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 37 | + IWorkbook workbook = application.Workbooks.Open("Input.xlsx"); |
| 38 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 39 | + |
| 40 | + //Get the chart name |
| 41 | + string chartName = worksheet.Charts[0].Name; |
| 42 | + //Display the chart name |
| 43 | + Console.WriteLine("The name of the chart is: " + chartName); |
| 44 | + |
| 45 | + //Saving the workbook |
| 46 | + workbook.SaveAs("Output.xlsx"); |
| 47 | +} |
| 48 | +{% endhighlight %} |
| 49 | + |
| 50 | +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} |
| 51 | +Using excelEngine As New ExcelEngine() |
| 52 | + ' Access the IApplication instance |
| 53 | + Dim application As IApplication = excelEngine.Excel |
| 54 | + |
| 55 | + ' Set the default version |
| 56 | + application.DefaultVersion = ExcelVersion.Xlsx |
| 57 | + |
| 58 | + ' Open the input workbook |
| 59 | + Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx") |
| 60 | + |
| 61 | + ' Get the first worksheet |
| 62 | + Dim worksheet As IWorksheet = workbook.Worksheets(0) |
| 63 | + |
| 64 | + ' Get the chart name |
| 65 | + Dim chartName As String = worksheet.Charts(0).Name |
| 66 | + |
| 67 | + ' Display the chart name |
| 68 | + Console.WriteLine("The name of the chart is: " & chartName) |
| 69 | + |
| 70 | + ' Save the workbook to output |
| 71 | + workbook.SaveAs("Output.xlsx") |
| 72 | +End Using |
| 73 | +{% endhighlight %} |
| 74 | +{% endtabs %} |
| 75 | + |
| 76 | +A complete working example in C# is present on <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/master/FAQ/Chart/.NET/ChartNameInWorksheet">this GitHub page</a>. |
0 commit comments