我想用“条款”和“ Commloans”创建两个选项卡。 但是,当我使用此代码时,“条款”将覆盖“ Commloans”,而我没有这两个选项卡:/
library("openxlsx")
write.xlsx(Comms, file = "PnL.xlsx", sheetName="Commloans", append=TRUE)
write.xlsx(Terms, file = "PnL.xlsx", sheetName="Terms", append=TRUE)
答案 0 :(得分:0)
没有reprex很难回答,但是我想如果您从第一个调用中删除append = TRUE
而仅将其留在第二个调用上,则应该使用xlsx
包
所以...
xlsx::write.xlsx(Comms, file = "PnL.xlsx", sheetName="Commloans")
xlsx::write.xlsx(Terms, file = "PnL.xlsx", sheetName="Terms", append=TRUE)
答案 1 :(得分:0)
您需要先创建一些工作表,然后使用write.xlsx
。看到这个答案;
R: easy way to export multiple data.frame to multiple excel worksheets?
我建议使用openxlsx
软件包
library(openxlsx)
# Create a blank workbook
OUT <- createWorkbook()
# Add some sheets to the workbook
addWorksheet(OUT, "Sheet 1 Name")
addWorksheet(OUT, "Sheet 2 Name")
# Write the data to the sheets
writeData(OUT, sheet = "Sheet 1 Name", x = dataframe1)
writeData(OUT, sheet = "Sheet 2 Name", x = dataframe2)
# Export the file
saveWorkbook(OUT, "My output file.xlsx")