如何使用officeR添加超链接?在ReporteRs包中有一个带有超链接参数的POT;但我在OfficeR包中没有看到任何远程关闭的东西。
答案 0 :(得分:2)
您是否找到了解决问题的方法?我写了一个函数来添加到文档的超链接。但是,您必须在模板docx文件中创建超链接的样式
from hdfs import InsecureClient
client = InsecureClient('http://0.0.0.0:50070')
with client.read('/test-storage/LICENSE.txt') as reader:
features = reader.read()
print(features)
可能有一个更好的解决方案,但它对我有用。
答案 1 :(得分:0)
@happ为Word文档提供了一个很好的解决方案(可能是问题的出处),但我认为值得一提的是,它具有向PowerPoint文件添加超链接的功能。
https://davidgohel.github.io/officer/reference/ph_hyperlink.html
fileout <- tempfile(fileext = ".pptx")
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with_text(x = doc, type = "title", str = "Un titre 1")
slide_summary(doc) # read column ph_label here
#> type id ph_label offx offy cx cy text
#> 1 title 2 Title 1 0.5 0.3003478 9 1.25 Un titre 1
doc <- ph_hyperlink(x = doc, ph_label = "Title 1",href = "https://cran.r-project.org")
print(doc, target = fileout )#> [1] "/private/var/folders/08/2qdvv0q95wn52xy6mxgj340r0000gn/T/RtmpXIYvn5/filef90c6579a4d2.pptx"
答案 2 :(得分:0)
我能够使用以下代码在 docx 中添加超链接(请参阅 https://rdrr.io/cran/officer/man/slip_in_text.html):
library(officer)
x <- read_docx()
x <- body_add_par(x, "Hello ", style = "Normal")
x <- slip_in_text(x, "world", style = "strong")
x <- slip_in_text(x, "Message is", style = "strong", pos = "before")
x <- slip_in_text(x, "with a link", style = "strong",
pos = "after", hyperlink = "https://davidgohel.github.io/officer/")
print(x, target = tempfile(fileext = ".docx"))