Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将单行添加到xlsx保留格式_R_Xlsx - Fatal编程技术网

R 将单行添加到xlsx保留格式

R 将单行添加到xlsx保留格式,r,xlsx,R,Xlsx,我想用R来附加一个xlsx文件,它有一行3列宽。xlsx文件有一些我不想丢失的格式。xlsx包的read.xlsx中的追加选项与read.table中的追加方式不同。从我所读到的内容来看,它是用于附加表单的 library(xlsx) ## I have an xlsx similar to this but with highlighting and such write.xlsx(mtcars[1:3, 1:3], "test.xlsx", row.names=FALSE) ## Row

我想用R来附加一个xlsx文件,它有一行3列宽。xlsx文件有一些我不想丢失的格式。
xlsx
包的
read.xlsx
中的追加选项与
read.table
中的追加方式不同。从我所读到的内容来看,它是用于附加表单的

library(xlsx)
## I have an xlsx similar to this but with highlighting and such
write.xlsx(mtcars[1:3, 1:3], "test.xlsx", row.names=FALSE)

## Row I want to append
mtcars[4, 1:3]
如何在不破坏格式(突出显示等)的情况下将此行添加到xlsx文件中。我目前正试图使用
xlsx
包来实现这一点,但我不同意使用它

追加错误,这是预期的,因为
append
在图纸上工作:

> write.xlsx(mtcars[4, 1:3], "test.xlsx", append=TRUE, row.names=FALSE)
Error in .jcall(wb, "Lorg/apache/poi/ss/usermodel/Sheet;", "createSheet",  : 
  java.lang.IllegalArgumentException: The workbook already contains a sheet of this name

以下是使用
XLConnect
软件包中的
appendworkeep
的解决方案:

library(XLConnect)
# mtcars xlsx file from demoFiles subfolder of package XLConnect
demoExcelFile <- system.file("demoFiles/mtcars.xlsx", package = "XLConnect")
wb <- loadWorkbook(demoExcelFile)
appendWorksheet(wb, mtcars, sheet = "mtcars")
saveWorkbook(wb,demoExcelFile)
库(XLConnect)
#程序包XLConnect的demoFiles子文件夹中的mtcars xlsx文件

demoExcelFile工作起来很有魅力。谢谢