Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

how to create hyperlinks in R to move to the next sheet

I need help in R.

I have data of 3 departments sales, marketing, accounts data. When exporting these data into excel, my desired output looks like of in the first sheet I need 3 rows of data i.e.: sales, marketing, accounts.

These 3 rows contains hyperlinks to the next sheets When I click into sales it will takes me into the sales sheet as well as remaining.

Can any one help how this can be done? Any help would be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To link to another sheet, use

addHyperlink(cell, "sheetname!colRow", linkType="DOCUMENT") 

For example

library(xlsx) 
wb <- createWorkbook() 
sheet1 <- createSheet(wb, "Sheet1") 
sheet2 <- createSheet(wb, "Sheet2") 
rows <- createRow(sheet1, 1:10) # 10 rows 
cells <- createCell(rows, colIndex=1:8) # 8 columns 

row <- 1
link <- paste0(names(getSheets(wb))[2], "!", "A", row)
setCellValue(cells[[row,1]], "link to other sheet") 
addHyperlink(cells[[row,1]], link, linkType="DOCUMENT") 

saveWorkbook(wb, "links.xlsx") 
shell.exec("links.xlsx")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...