11

I was trying to write a dataframe with 523370 rows and 3 columns using write.xlsx

write.xlsx(x = dataframe, file = "dataframe.xlsx",
+ sheetName = "dataframe1", row.names = FALSE)

but 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">

and I check these question :

But that changed the error changed to:

Error in .jcheck(silent = FALSE) :Java Exception <no description because toString() failed>.jcall(row[[ir]], "Lorg/apache/poi/ss/usermodel/Cell;", "createCell", as.integer(colIndex[ic] - 1))<S4 object of class "jobjRef">
3
  • 2
    unfortunately no answer, but an alternative is to try write.xlsx from package openxlsx github.com/awalker89/openxlsx
    – ckluss
    Jan 3, 2015 at 16:12
  • thanks for your comment @ChristofKluß.it didn't find write.xlsx as a command. but the problem here I have was the volume of the dataframe and I have to split the dataframe.and save them in diffrent sheet using WriteXLS. Jan 3, 2015 at 19:16
  • I have noticed this happens when you use both dplyr and xlsx packages, There might be a conflict between then.
    – Luizedu
    May 27, 2019 at 19:26

6 Answers 6

18

I had the same problem and restarting R did the trick.

If you're using RStudio the keystroke shortcut for restarting R is Ctrl + Shift + F10 (PC) or Command + Shift + F10 (Mac).

1
  • 2
    I've had similar errors before and restarting also worked for me.
    – Bobby
    Nov 1, 2016 at 13:57
15

Try to use write.xlsx from openxlsx package that does not use java.

openxlsx::write.xlsx(x = dataframe, file = "dataframe.xlsx")
1
  • 1
    openxlsx also has much of the same functionality of the XLSX package, including the ability to add multiple sheets. openxlsx does not suffer from those odd java errors.
    – DanWaters
    Sep 28, 2020 at 14:17
2

Use this line :

openxlsx::write.xlsx(x = dataframe, file = "dataframe.xlsx")

It worked for me ...

0

I get the same error when I use the relative path. You can try to use the absolute paths.

  • R version 3.4.4 (2018-03-15)
  • Platform: x86_64-pc-linux-gnu (64-bit)
  • Running under: Ubuntu 16.04.4 LTS
1
  • Welcome to SO. Have a look at the formatting options. This will help you post better answers/questions.
    – petezurich
    Jul 23, 2018 at 4:54
-3

I had a similar problem and used write.csv() instead and then saved the csv file as .xlsx from excel. That did the trick.

-4

You can always use read.csv() and then just save it and a xlsx file if the problem continues.

Not the answer you're looking for? Browse other questions tagged or ask your own question.