Get Worksheet of the Chart with C++
The following example shows how to use the Chart::GetWorksheet method. 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::GetWorksheet method.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace std;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Create workbook from sample Excel file
Workbook workbook(srcDir + u"sample.xlsx");
// Access first worksheet of the workbook
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Print worksheet name
cout << "Sheet Name: " << worksheet.GetName().ToUtf8() << endl;
// Access the first chart inside this worksheet
Chart chart = worksheet.GetCharts().Get(0);
// Access the chart's sheet and display its name again
cout << "Chart's Sheet Name: " << chart.GetWorksheet().GetName().ToUtf8() << endl;
Aspose::Cells::Cleanup();
return 0;
}
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