Get Worksheet of the Chart
The following example shows how to use the Chart.Worksheet property. The code first prints the name of the worksheet, then accesses the first chart on the worksheet. It then prints the worksheet name again, using the Chart.Worksheet property.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from sample Excel file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet of the workbook | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Print worksheet name | |
Console.WriteLine("Sheet Name: " + worksheet.Name); | |
// Access the first chart inside this worksheet | |
Chart chart = worksheet.Charts[0]; | |
// Access the chart's sheet and display its name again | |
Console.WriteLine("Chart's Sheet Name: " + chart.Worksheet.Name); |
Below is the console output that the sample code results in. As you can see, it prints the same worksheet name both times.
Sheet Name: Portfolio
Chart's Sheet Name: Portfolio