简体   繁体   English

在 write.xlsx 中使用 xlsx 包时出错

[英]Error when using xlsx package in write.xlsx

I am trying to save a file using write.xslx (when saving with write.csv some row got shift in more columns so I am trying to save the file as xlsx directly).我想保存文件使用write.xslx (与保存时write.csv一些排在了多个列移位,所以我想直接保存文件为XLSX)。 If I type this command:如果我输入这个命令:

    write.xlsx (old.data, file ="Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)

or或者

    write.xlsx (old.data, "Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)

I get this error:我收到此错误:

Error in .jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook") : Java Exception <no description because toString() failed>.jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook")<S4 object of class "jobjRef"> .jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook") 中的错误:Java 异常 <没有描述,因为 toString() 失败>.jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook")<S4类“jobjRef”> 的对象

Can anyone help me sort it out?谁能帮我整理一下?

I don't think that this question can easily be answered.我认为这个问题不容易回答。 Is <working_directory>/Documents writeable to you? <working_directory>/Documents写入? Can you create the file你能创建文件吗

write.xlsx ( data.frame( a = 1:10, row.names = letters[ 1:10 ] ), "Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)

If this works, but with old.data it doesn't you have to provide a reproducible example .如果这有效,但使用old.data则不必提供可重现的示例

However, I experienced every here and again weird problems with the xlsx package.但是,我一次又一次地遇到了xlsx包的奇怪问题。 From my experience XLConnect is much more robust and bug-free:根据我的经验, XLConnect更加强大且没有错误:

library("XLConnect")
writeWorksheetToFile( "Documents/newxlsx", old.data, "Sheet1", header=TRUE, rownames = "rownames.header" )

write_xlsx() from the writexl package works great for me and is way faster! write_xlsx()包中的write_xlsx()对我来说非常writexl ,而且速度更快! It also works fine with tibbles and does not have the annoying errors or resctrictions from the xlsx package.它也适用于 tibbles,并且没有来自xlsx包的烦人的错误或限制。 It is also completely written in C so no Java, Perl or Rtools are required.它也是完全用 C 编写的,因此不需要 Java、Perl 或 Rtools。

For more info see https://ropensci.org/technotes/2017/09/08/writexl-release/有关更多信息,请参阅https://ropensci.org/technotes/2017/09/08/writexl-release/

I just had this same problem.我刚刚遇到了同样的问题。 I think there might be a bug with openXL but I love working with it.我认为 openXL 可能存在错误,但我喜欢使用它。 So I open and close R and then change the wd, saved the file exactly where the wd was and then I run the exact same code again.因此,我打开并关闭 R,然后更改 wd,将文件保存在 wd 所在的位置,然后再次运行完全相同的代码。 It worked.有效。

Today I had that problem after deployment.今天我在部署后遇到了这个问题。 At this moment I didn't need to change package and stick to xlsx I updated dplyr, xlsx, and the one that did the trick was updating rjava.此刻我不需要更改包并坚持使用 xlsx 我更新了 dplyr、xlsx,而解决问题的方法是更新 rjava。 Since it was a conflict with java and xlsx calls it, I gave it a shot.由于它与java和xlsx调用它有冲突,所以我试了一下。

Hope this work for you too希望这对你也有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM