获取图表的工作表
Contents
[
Hide
]
有时,您想要从图表的参考访问工作表。 Aspose.Cells 提供了图表.工作表返回包含图表的工作表的引用的属性。
下面的例子展示了如何使用图表.工作表财产。该代码首先打印工作表的名称,然后访问工作表上的第一个图表。然后它再次打印工作表名称,使用图表.工作表财产。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
下面是示例代码生成的控制台输出。如您所见,它两次打印相同的工作表名称。
Sheet Name: Portfolio
Chart's Sheet Name: Portfolio