【问题标题】:openxlsx workbook: multiple hyperlinks in one cellopenxlsx 工作簿:一个单元格中的多个超链接
【发布时间】:2022-01-14 11:58:14
【问题描述】:

我尝试使用 openxlsx 包在同一个 Excel 单元格中添加多个超链接但未成功(由于我的工作流程的其余部分,使用 openxlsx 对我来说很重要)。

知道如何实现吗?

【问题讨论】:

  • 能否请您提供一个可重现的示例来展示您的尝试?

标签: r openxlsx


【解决方案1】:

也许结合使用 stingr 包的 str_glue 并指定换行文本样式或设置列宽? str_glue 允许“硬返回”。我不确定超链接是否有效,但我没有 excel 来对其进行全面测试。

library(openxlsx)
library(stringr)
x <- str_glue("https://www.google.com
              https://www.yahoo.com")

class(x) <- "hyperlink"

wb <- createWorkbook()
addWorksheet(wb, "Sheet1")
wraptext <- createStyle(wrapText = TRUE)


## External Hyperlink

writeData(wb, sheet = 1, x = x, startCol = 10)

addStyle(wb, "Sheet1", wraptext, cols = 10, rows = 1)
setColWidths(wb, "Sheet1", cols = 10, widths = 25)

openXL(wb)

【讨论】:

    猜你喜欢
    • 2017-09-29
    • 2021-01-07
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多