0

我想知道当我单击单元格 1 表 a (A2、A3 等)时,是否可以设置一个链接,将我重定向到单元格 id1 表 b (A1、B1 等)?

(或者必须更好地创建从第 2,3 行等表 a 到列 A、B 等表 b 的链接)

library(openxlsx)

a <- data.frame("id" = 1:2, "val" = paste0(1:2, "a"))
b <- data.frame("id1" = 1:5, "id2" = 11:15)

sheets <- list(
  "a" = "a",
  "b" = "b")

wb <- openxlsx::createWorkbook()
addWorksheet(wb, sheets$a)
addWorksheet(wb, sheets$b)

writeData(wb, sheet = sheets$a, x = a, startRow = 1)
writeData(wb, sheet = sheets$b, x = b, startRow = 1)

saveWorkbook(wb, "inst/test/file.xlsx", overwrite = T)
4

1 回答 1

1

写入数据后,但在保存工作簿之前,请执行以下操作:

for(i in seq_along(a$id))
{
  link <- makeHyperlinkString(sheets$b, row = 1, col = i, text = a$id[i])
  writeFormula(wb, sheets$a, link, startCol = 1, startRow = i + 1)
}
于 2020-01-14T10:41:03.373 回答