XLConnect超链接

我正在创build一个程序,该程序将生成一个质量评估数据集的样本。 实际数据将在我们的Intranet上提供。 这个示例以非常特别的用户友好格式输出。 我想要使​​用XLconnect添加超链接到基于示例的Excel文档。 我一直无法find答案使用几个search。 我希望这是可能的使用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) 

你必须使用

setCellFormula()

 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)