在R中使用openxlsx包而不是xlsx包进行循环

时间:2020-03-20 05:18:03

标签: r openxlsx

是否可以使用openxlsx软件包编写以下代码?我卡在createRow行中,因为我认为openxlsx没有此功能。

library(xlsx)


linkname = data.frame(fulllist=c("First","Second","Third","Fourth","Fifth"), hyplink=c("http://first.com/","http://second.com","http://third.com","http://fourth.com","http://fifth.com"),stringsAsFactors = F)

wb <- createWorkbook()
sheet1 <- createSheet(wb, "Sheet1")
rows <- createRow(sheet1, seq_along(linkname$hyplink))
rows <- createRow(sheet1, 1:5)
cells <- createCell(rows, colIndex=1:2) # 2 columns
for (i in seq_along(cells[,1])){
  col1 <- cells[[i,1]]
  setCellValue(col1, linkname$fulllist[i])
  addHyperlink(col1,linkname$hyplink[i])
  col2 <- cells[[i,2]]
  setCellValue(col2,linkname$fulllist[i])

}
saveWorkbook(wb, "C:/Users/K/Downloads/test.xlsx")

0 个答案:

没有答案
相关问题