0

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). 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">

Can anyone help me sort it out?

Heikki
  • 2,214
  • 19
  • 34
flacchy
  • 511
  • 1
  • 6
  • 9

4 Answers4

1

I don't think that this question can easily be answered. Is <working_directory>/Documents writeable to you? 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.

However, I experienced every here and again weird problems with the xlsx package. From my experience XLConnect is much more robust and bug-free:

library("XLConnect")
writeWorksheetToFile( "Documents/newxlsx", old.data, "Sheet1", header=TRUE, rownames = "rownames.header" )
Community
  • 1
  • 1
Beasterfield
  • 7,023
  • 2
  • 38
  • 47
  • Thanks, the XLConnect is for the r v3 and I am using other package in v2. anyway I solve it using csv file and using as separator ";" now my file is working.thank you so much for the advice. – flacchy Feb 12 '14 at 10:30
  • @user2452520 What is v3 and what is v2? – Beasterfield Feb 12 '14 at 12:07
0

write_xlsx() from the writexl package works great for me and is way faster! It also works fine with tibbles and does not have the annoying errors or resctrictions from the xlsxpackage. It is also completely written in C so no Java, Perl or Rtools are required.

For more info see https://ropensci.org/technotes/2017/09/08/writexl-release/

0

I just had this same problem. I think there might be a bug with openXL but I love working with it. 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. It worked.

Arual
  • 12
  • 4
0

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. Since it was a conflict with java and xlsx calls it, I gave it a shot.

Hope this work for you too

Mikael
  • 113
  • 1
  • 8