Create PdfBookmarkEntry for Chart Sheet
Possible Usage Scenarios
Earlier, Aspose.Cells for Python via .NET would create PdfBookmarkEntry for a normal sheet. But now Aspose.Cells for Python via .NET 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
from aspose.cells import PdfSaveOptions, Workbook | |
from aspose.cells.rendering import PdfBookmarkEntry | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load sample Excel file | |
wb = Workbook("sampleCreatePdfBookmarkEntryForChartSheet.xlsx") | |
# Access all four worksheets | |
sheet1 = wb.worksheets[0] | |
sheet2 = wb.worksheets[1] | |
sheet3 = wb.worksheets[2] | |
sheet4 = wb.worksheets[3] | |
# Create Pdf Bookmark Entry for Sheet1 | |
ent1 = PdfBookmarkEntry() | |
ent1.destination = sheet1.cells.get("A1") | |
ent1.text = "Bookmark-I" | |
# Create Pdf Bookmark Entry for Sheet2 - Chart | |
ent2 = PdfBookmarkEntry() | |
ent2.destination = sheet2.cells.get("A1") | |
ent2.text = "Bookmark-II-Chart1" | |
# Create Pdf Bookmark Entry for Sheet3 | |
ent3 = PdfBookmarkEntry() | |
ent3.destination = sheet3.cells.get("A1") | |
ent3.text = "Bookmark-III" | |
# Create Pdf Bookmark Entry for Sheet4 - Chart | |
ent4 = PdfBookmarkEntry() | |
ent4.destination = sheet4.cells.get("A1") | |
ent4.text = "Bookmark-IV-Chart2" | |
# Arrange all Bookmark Entries | |
lst = [] | |
ent1.sub_entry = lst | |
lst.append(ent2) | |
lst.append(ent3) | |
lst.append(ent4) | |
# Create Pdf Save Options with Bookmark Entries | |
opts = PdfSaveOptions() | |
opts.bookmark = ent1 | |
# Save the output Pdf | |
wb.save("outputCreatePdfBookmarkEntryForChartSheet.pdf", opts) |