Create PdfBookmarkEntry for Chart Sheet with C++
Possible Usage Scenarios
Earlier, Aspose.Cells would create PdfBookmarkEntry for a normal sheet. But now Aspose.Cells can also create PdfBookmarkEntry for chart sheet. Since chart sheet does not have any other cell except cell A1, so it will create PdfBookmarkEntry for cell A1 only.
Create PdfBookmarkEntry for Chart Sheet
The following sample code loads the sample Excel file which has four sheets. Two of them are normal sheets and the other two are chart sheets. It creates four bookmark entries as follows:
- Bookmark-I
- Bookmark-II-Chart1
- Bookmark-III
- Bookmark-IV-Chart2
The following screenshot shows the output PDF generated by the sample code for a reference.
Sample Code
#include <iostream>
#include <vector>
#include <memory>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Rendering;
int main()
{
Aspose::Cells::Startup();
// Load sample Excel file
U16String inputFilePath = u"sampleCreatePdfBookmarkEntryForChartSheet.xlsx";
Workbook wb(inputFilePath);
// Access all four worksheets
WorksheetCollection sheets = wb.GetWorksheets();
Worksheet sheet1 = sheets.Get(0);
Worksheet sheet2 = sheets.Get(1);
Worksheet sheet3 = sheets.Get(2);
Worksheet sheet4 = sheets.Get(3);
// Create Pdf Bookmark Entry for Sheet1
PdfBookmarkEntry ent1;
ent1.SetDestination(sheet1.GetCells().Get(u"A1"));
ent1.SetText(u"Bookmark-I");
// Create Pdf Bookmark Entry for Sheet2 - Chart
PdfBookmarkEntry ent2;
ent2.SetDestination(sheet2.GetCells().Get(u"A1"));
ent2.SetText(u"Bookmark-II-Chart1");
// Create Pdf Bookmark Entry for Sheet3
PdfBookmarkEntry ent3;
ent3.SetDestination(sheet3.GetCells().Get(u"A1"));
ent3.SetText(u"Bookmark-III");
// Create Pdf Bookmark Entry for Sheet4 - Chart
PdfBookmarkEntry ent4;
ent4.SetDestination(sheet4.GetCells().Get(u"A1"));
ent4.SetText(u"Bookmark-IV-Chart2");
// Arrange all Bookmark Entries
std::vector<PdfBookmarkEntry> lst;
lst.push_back(ent2);
lst.push_back(ent3);
lst.push_back(ent4);
// Create Pdf Save Options with Bookmark Entries
PdfSaveOptions opts;
opts.SetBookmark(ent1);
// Save the output Pdf
U16String outputFilePath = u"outputCreatePdfBookmarkEntryForChartSheet.pdf";
wb.Save(outputFilePath, opts);
std::cout << "PDF with bookmarks created successfully!" << std::endl;
Aspose::Cells::Cleanup();
return 0;
}