我想创建两个带有条款和Commloans的选项卡。但是当我使用此代码时,条款会覆盖 Commloans,我没有这两个选项卡:/
library("openxlsx")
write.xlsx(Comms, file = "PnL.xlsx", sheetName="Commloans", append=TRUE)
write.xlsx(Terms, file = "PnL.xlsx", sheetName="Terms", append=TRUE)
没有reprex很难回答,但我想如果你append = TRUE
从第一个电话中删除并只保留第二个电话,这应该可以使用xlsx
包
所以...
xlsx::write.xlsx(Comms, file = "PnL.xlsx", sheetName="Commloans")
xlsx::write.xlsx(Terms, file = "PnL.xlsx", sheetName="Terms", append=TRUE)
您需要先创建一些工作表,然后使用write.xlsx
. 看到这个答案;
R:将多个data.frame导出到多个excel工作表的简单方法?
我建议使用该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")