【问题标题】:How to include hyperlinks in flextable?如何在 flextable 中包含超链接?
【发布时间】:2018-03-06 06:45:09
【问题描述】:

我正在尝试使用官员制作一个 powerpoint 文件,其中包含在其单元格中带有超链接的表格,但我找不到如何做到这一点的方法。

例如幻灯片上 2 列表格中的一行可以在第一列中包含“Ensembl”,第二列会显示“ENSG00000165025”,单击它会在“uswest.ensembl.org/Homo_sapiens/Gene/Summary”中打开浏览器?g=ENSG00000165025'。第二列中的某些值可能只是纯文本。

这有可能实现吗?

【问题讨论】:

  • 这是不可能的,但我会实现它(并在它准备好时回答这个问题)
  • 真的很棒!它会很好地增强库的功能。谢谢,杰森

标签: r flextable officer


【解决方案1】:

使用 github 上的新版本,您将能够在下面的演示中包含超链接:

library(flextable)
dat <- data.frame(
  col = "CRAN website", href = "https://cran.r-project.org",
  stringsAsFactors = FALSE)

ft <- flextable(dat)
ft <- display(
  ft, col_key = "col", pattern = "# {{mylink}}",
  formatters = list(mylink ~ hyperlinked_text(href, col) )
)
ft

【讨论】:

  • 该更新适用于简单的 url,但例如:entrez 将在 ph_at_flextable 将 flextable 包含在 rpptx 对象中时给出解析错误。 URLencode 可以修复这个解析错误,但是现在 flextable 坏了,点击链接不会打开网页。
  • 你能提供一个可重现的例子吗?
【解决方案2】:

`

dat <- data.frame(
    col = "entrez", 
    href = "https://www.ncbi.nlm.nih.gov/gene?cmd=Retrieve&dopt=full_report&list_uids=6850", 
    stringsAsFactors = FALSE)

ft <- flextable(dat)
ft <- display(
    ft, col_key = "col", pattern = "# {{mylink}}",
    formatters = list(mylink ~ hyperlink_text(href, col) )
)
ft # works fine

doc <- read_pptx() %>% 
    add_slide(layout = 'Title and Content', 'Office Theme') %>% 
    ph_with_flextable(ft) # error

doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html, : EntityRef: 期待 ';' [23]

重复:

dat <- data.frame(
    col = "entrez", href = URLencode("https://www.ncbi.nlm.nih.gov/gene?cmd=Retrieve&dopt=full_report&list_uids=6850", reserved = TRUE),
    stringsAsFactors = FALSE)

ft <- flextable(dat)
ft <- display(
    ft, col_key = "col", pattern = "# {{mylink}}",
    formatters = list(mylink ~ hyperlink_text(href, col) )
)
ft # clicking the link in rstudio fails

doc <- read_pptx() %>% 
    add_slide(layout = 'Title and Content', 'Office Theme') %>% 
    ph_with_flextable(ft) # fine, no error message, but error message when opening pp file

【讨论】:

  • 刚刚在 github 上修复了这个问题。请注意,某些配置中的 URL 和 pptx/word 存在问题。例如,我可以使用“google.fr/search?source=hp&q=officer+R+package”,但不能使用您的。来自MS网站,通过officeversion &gt;= 2016解决
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
  • 2018-06-12
  • 1970-01-01
相关资源
最近更新 更多