Java – use write Xlsx replace the existing worksheet with R package xlsx

I am using package xlsx version: 0.0 7 date: August 1, 2014 In R version 3.0 1 (May 16, 2013) – good sport platform: i386-w64-mingw32 / i386 (32-bit)

I have a xlsx file with at least two (such as a and b) I need to read data from a, edit them and save them in B This must be done on the basis of journals

I can use read Xlsx reads data from a After editing the data frame, I want to save it in an existing worksheet B in the same xlsx file

I tried to use this line

write.xlsx(down,paste0(root,'/registration reports/registration complete_WK.xlsx'),sheet="data_final",col.names=T,row.names=F,append=T,showNA=F)

But it gave me this mistake:

I really need to replace the existing paper many times How can I do this?

Thank you, Filippo

Solution

If you want to save the new data frame in an existing excel file, you must first load the xlsx file:

wb <- loadWorkbook(file)

What sheets do you have that you get:

sheets <- getSheets(wb)

You can easily delete and add (and therefore replace) worksheets:

removeSheet(wb,sheetName="Sheet1")
yourSheet <- createSheet(wb,sheetName="Sheet1")

You can populate the worksheet with data frames:

addDataFrame(yourDataFrame,yourSheet,<options>)
addDataFrame(anotherDataFrame,startRow=nrow(yourDataFrame)+2)

The final step is to save the entire workbook as xlsx:

saveWorkbook(wb,file)

By the way: the xlsx package documentation is very good and helpful for these problems:) http://cran.r-project.org/web/packages/xlsx/xlsx.pdf

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>