如何将超链接添加到 pptx python 上 table 单元格中的文本?
How to add a Hyperlink to a text in table cell on pptx python?
我正在 pptx-python 中创建报告。
我正在尝试将 hyperlink 添加到 table 单元格之一。
有人知道我该怎么做吗?
这是我的代码:
prs = Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)
title_only_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(title_only_slide_layout)
shapes = slide.shapes
rows = 2
cols = 1
left = Inches(0.5)
top = Inches(1.5)
width = Inches(15)
height = Inches(0.8)
table = shapes.add_table(rows, cols, left, top, width, height).table
table.cell(0,0).text = 'title'
table.cell(1,0).text = 'link'
我希望 link 文本是超文本link。
我将不胜感激 :)
添加超链接有点棘手。您首先需要在文本中添加一个“运行”,添加要显示的文本,然后添加超链接地址。例如:
cell = table.cell(0,1)
cell_link = cell.text_frame.paragraphs[0].add_run()
cell_link.text = "Text to display"
hlink = cell_link.hyperlink
hlink.address = "https://www.somwehere.com"
我正在 pptx-python 中创建报告。 我正在尝试将 hyperlink 添加到 table 单元格之一。 有人知道我该怎么做吗? 这是我的代码:
prs = Presentation()
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)
title_only_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(title_only_slide_layout)
shapes = slide.shapes
rows = 2
cols = 1
left = Inches(0.5)
top = Inches(1.5)
width = Inches(15)
height = Inches(0.8)
table = shapes.add_table(rows, cols, left, top, width, height).table
table.cell(0,0).text = 'title'
table.cell(1,0).text = 'link'
我希望 link 文本是超文本link。 我将不胜感激 :)
添加超链接有点棘手。您首先需要在文本中添加一个“运行”,添加要显示的文本,然后添加超链接地址。例如:
cell = table.cell(0,1)
cell_link = cell.text_frame.paragraphs[0].add_run()
cell_link.text = "Text to display"
hlink = cell_link.hyperlink
hlink.address = "https://www.somwehere.com"