Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R Excel中Openxlsx超链接输出显示_R_Excel_Openxlsx - Fatal编程技术网

R Excel中Openxlsx超链接输出显示

R Excel中Openxlsx超链接输出显示,r,excel,openxlsx,R,Excel,Openxlsx,我试图在一个数据框中加入一个excel表格,它有两列 列A包含商店的名称 列B包含这些存储的URL 我想采取列A,使其成为一个可点击的超链接,所以它不是纯文本,它是一个超链接到商店网站 我尝试使用openxlsx包生成正确的输出 我尝试使用以下代码snip x <- c("https://www.google.com", "https://www.google.com.au") names(x) <- c("google", "google Aus") class(x) <-

我试图在一个数据框中加入一个excel表格,它有两列

列A包含商店的名称 列B包含这些存储的URL

我想采取列A,使其成为一个可点击的超链接,所以它不是纯文本,它是一个超链接到商店网站

我尝试使用openxlsx包生成正确的输出

我尝试使用以下代码snip

x <- c("https://www.google.com", "https://www.google.com.au")
names(x) <- c("google", "google Aus")
class(x) <- "hyperlink"

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

x使用
openxlsx
的方法:

library(openxlsx)
library(dplyr)

# create sample data
df <- data.frame(
  site_name = c("Zero Hedge", "Free Software Foundation"),
  site_url = c("https://www.zerohedge.com", "https://www.fsf.org")
)

# add new column that manually constructs Excel hyperlink formula
# note backslash is required for quotes to appear in Excel
df <- df %>%
  mutate(
    excel_link = paste0(
      "HYPERLINK(\"",
      site_url,
      "\", \"",
      site_name,
      "\")"
    )
  )

# specify column as formula per openxlsx::writeFormula option #2
class(df$excel_link) <- "formula"

# create and write workbook
wb <- createWorkbook()
addWorksheet(wb, "df_sheet")
writeData(wb, "df_sheet", df)
saveWorkbook(wb, "wb.xlsx", overwrite = TRUE)
库(openxlsx)
图书馆(dplyr)
#创建示例数据

df为了使该文件可复制,您能否与
head(dput(df))
共享部分
df
?是的,我会给您一个reprex。我需要整理数据集。为了举例,我改变了我的数据。我会做一个假人,给你一个reprex。
library(openxlsx)
library(dplyr)

# create sample data
df <- data.frame(
  site_name = c("Zero Hedge", "Free Software Foundation"),
  site_url = c("https://www.zerohedge.com", "https://www.fsf.org")
)

# add new column that manually constructs Excel hyperlink formula
# note backslash is required for quotes to appear in Excel
df <- df %>%
  mutate(
    excel_link = paste0(
      "HYPERLINK(\"",
      site_url,
      "\", \"",
      site_name,
      "\")"
    )
  )

# specify column as formula per openxlsx::writeFormula option #2
class(df$excel_link) <- "formula"

# create and write workbook
wb <- createWorkbook()
addWorksheet(wb, "df_sheet")
writeData(wb, "df_sheet", df)
saveWorkbook(wb, "wb.xlsx", overwrite = TRUE)