if (FALSE) {
# Load workbook (create if not existing)
wb <- loadWorkbook("setHyperlink.xlsx", create = TRUE)
# Create a sheet named 'mtcars'
createSheet(wb, name = "mtcars")
# Write built-in data set 'mtcars' to the above defined worksheet
writeWorksheet(wb, mtcars, sheet = "mtcars", rownames = "Car")
# Set hyperlinks
links <- paste0("https://www.google.com?q=", gsub(" ", "+", rownames(mtcars)))
setHyperlink(wb, sheet = "mtcars", row = seq_len(nrow(mtcars)) + 1, col = 1,
type = XLC$HYPERLINK.URL, address = links)
# Save workbook (this actually writes the file to disk)
saveWorkbook(wb)
# clean up
file.remove("setHyperlink.xlsx")
}
Run the code above in your browser using DataLab