R XLConnect超链接

R XLConnect超链接,r,excel,xlconnect,R,Excel,Xlconnect,我正在创建一个程序,该程序将生成一个用于质量审查的数据集样本。实际数据将在我们的内部网上提供。此示例以一种非常特定的用户友好格式输出到excel中。我想使用XLconnect根据示例向excel文档添加超链接。我无法通过多次搜索找到答案。我希望这是可能的使用XLconnect或类似的软件包,将保持在excel格式。我下面的代码只添加文本,但不添加超链接 library(XLConnect) Full_data_set = read.csv(paste(my.file.location, my.

我正在创建一个程序,该程序将生成一个用于质量审查的数据集样本。实际数据将在我们的内部网上提供。此示例以一种非常特定的用户友好格式输出到excel中。我想使用XLconnect根据示例向excel文档添加超链接。我无法通过多次搜索找到答案。我希望这是可能的使用XLconnect或类似的软件包,将保持在excel格式。我下面的代码只添加文本,但不添加超链接

library(XLConnect)

Full_data_set = read.csv(paste(my.file.location, my.set, sep= "/"))

my.sample <- sample(Full_data_set$groupid, 50)
my.link <- paste("ourwebsite.org/group/" my.sample, sep = "")


wb <- loadWorkbook(filename = "my.file.location/Template2.xlsx",
                   create = TRUE)

writeWorksheet(wb, my.links, sheet= 1,   
               startRow=3, startCol=3,            
               header=FALSE)  
saveWorkbook(wb)
库(XLConnect)
Full_data_set=read.csv(粘贴(my.file.location,my.set,sep=“/”)
my.sample您必须使用

setCellFormula()

库(“XLConnect”)

df Add hyperlink当前显示在xlconnect github页面上:请参阅:显示xlsx提供此功能的软件包。见:
library("XLConnect")

df <- data.frame(
      v1 = c("wiki", "google", "so"),
      v2 = c("https://www.wikipedia.org/",
             "https://www.google.com/",
             "http://stackoverflow.com/"),
      link = NA ,
      stringsAsFactors = F)

# Load workbook (create if not existing)
wb <- loadWorkbook("hlink_example.xlsx", create = TRUE)

# Create a sheet
createSheet(wb, name = "Sheet1")

# Create a named region on sheet
createName(wb, name = "Sheet1", formula = "Sheet1!$A$1")

# Write data set to the above defined named region
writeNamedRegion(wb, df, name = "Sheet1")

# Create an excel column ref. for formula and links in data frame
excelCol <- letters[which(names(df) == "v2")]

# Construct the input range & formula
formula  <- paste("HYPERLINK(",excelCol, 2:(nrow(df)+1),")", sep = "")

# Create the link column in data frame
df$link <- formula

# Set the cell formulas using index for rows/col
setCellFormula(wb, "Sheet1", 2:(nrow(df)+1), which(names(df) == "link"),
formula)

# Save workbook
saveWorkbook(wb)