“Error in addWorksheet(wb, ”sheet1“) : First argument must be a Workbook”
up vote
1
down vote
favorite
I am using ‘openxlsx’ package in R. ٰI want to add some data in xlsx file. I have used following code to create the workbook and add worksheet in it.
wb=createWorkbook()
addWorksheet(wb,"sheet 1")
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 1)
writeData(wb,sheet = 1,"To",startCol = 2,startRow = 1)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
saveWorkbook(wb,"file.xlsx",overwrite = TRUE)
This code was working well for a long time, But recently, I am facing this error
Error in addWorksheet(wb, "sheet 1") : First argument must be a
Workbook.
How this error will be resolved?
r rstudio xlsx r-xlsx openxlsx
add a comment |
up vote
1
down vote
favorite
I am using ‘openxlsx’ package in R. ٰI want to add some data in xlsx file. I have used following code to create the workbook and add worksheet in it.
wb=createWorkbook()
addWorksheet(wb,"sheet 1")
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 1)
writeData(wb,sheet = 1,"To",startCol = 2,startRow = 1)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
saveWorkbook(wb,"file.xlsx",overwrite = TRUE)
This code was working well for a long time, But recently, I am facing this error
Error in addWorksheet(wb, "sheet 1") : First argument must be a
Workbook.
How this error will be resolved?
r rstudio xlsx r-xlsx openxlsx
The code you have shared doesn't throw any error in my case. The error message you have shared indicates that the workbookwb
was not created. Maybe you skipped executing line 1 of the code.
– Rage
Nov 9 at 7:13
I have not skipped that line. Actually, this was working well but recently failed. but don't know why?
– Alvi
Nov 9 at 7:43
What doesstr(wb)
show?
– user2554330
Nov 9 at 10:19
Formal class 'jobjRef' [package "rJava"] with 2 slots ..@ jobj :<externalptr> ..@ jclass: chr "org/apache/poi/xssf/usermodel/XSSFWorkbook"
– Alvi
Nov 9 at 11:43
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using ‘openxlsx’ package in R. ٰI want to add some data in xlsx file. I have used following code to create the workbook and add worksheet in it.
wb=createWorkbook()
addWorksheet(wb,"sheet 1")
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 1)
writeData(wb,sheet = 1,"To",startCol = 2,startRow = 1)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
saveWorkbook(wb,"file.xlsx",overwrite = TRUE)
This code was working well for a long time, But recently, I am facing this error
Error in addWorksheet(wb, "sheet 1") : First argument must be a
Workbook.
How this error will be resolved?
r rstudio xlsx r-xlsx openxlsx
I am using ‘openxlsx’ package in R. ٰI want to add some data in xlsx file. I have used following code to create the workbook and add worksheet in it.
wb=createWorkbook()
addWorksheet(wb,"sheet 1")
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 1)
writeData(wb,sheet = 1,"To",startCol = 2,startRow = 1)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
writeData(wb,sheet = 1,"From",startCol = 1,startRow = 2)
saveWorkbook(wb,"file.xlsx",overwrite = TRUE)
This code was working well for a long time, But recently, I am facing this error
Error in addWorksheet(wb, "sheet 1") : First argument must be a
Workbook.
How this error will be resolved?
r rstudio xlsx r-xlsx openxlsx
r rstudio xlsx r-xlsx openxlsx
asked Nov 9 at 6:49
Alvi
38110
38110
The code you have shared doesn't throw any error in my case. The error message you have shared indicates that the workbookwb
was not created. Maybe you skipped executing line 1 of the code.
– Rage
Nov 9 at 7:13
I have not skipped that line. Actually, this was working well but recently failed. but don't know why?
– Alvi
Nov 9 at 7:43
What doesstr(wb)
show?
– user2554330
Nov 9 at 10:19
Formal class 'jobjRef' [package "rJava"] with 2 slots ..@ jobj :<externalptr> ..@ jclass: chr "org/apache/poi/xssf/usermodel/XSSFWorkbook"
– Alvi
Nov 9 at 11:43
add a comment |
The code you have shared doesn't throw any error in my case. The error message you have shared indicates that the workbookwb
was not created. Maybe you skipped executing line 1 of the code.
– Rage
Nov 9 at 7:13
I have not skipped that line. Actually, this was working well but recently failed. but don't know why?
– Alvi
Nov 9 at 7:43
What doesstr(wb)
show?
– user2554330
Nov 9 at 10:19
Formal class 'jobjRef' [package "rJava"] with 2 slots ..@ jobj :<externalptr> ..@ jclass: chr "org/apache/poi/xssf/usermodel/XSSFWorkbook"
– Alvi
Nov 9 at 11:43
The code you have shared doesn't throw any error in my case. The error message you have shared indicates that the workbook
wb
was not created. Maybe you skipped executing line 1 of the code.– Rage
Nov 9 at 7:13
The code you have shared doesn't throw any error in my case. The error message you have shared indicates that the workbook
wb
was not created. Maybe you skipped executing line 1 of the code.– Rage
Nov 9 at 7:13
I have not skipped that line. Actually, this was working well but recently failed. but don't know why?
– Alvi
Nov 9 at 7:43
I have not skipped that line. Actually, this was working well but recently failed. but don't know why?
– Alvi
Nov 9 at 7:43
What does
str(wb)
show?– user2554330
Nov 9 at 10:19
What does
str(wb)
show?– user2554330
Nov 9 at 10:19
Formal class 'jobjRef' [package "rJava"] with 2 slots ..@ jobj :<externalptr> ..@ jclass: chr "org/apache/poi/xssf/usermodel/XSSFWorkbook"
– Alvi
Nov 9 at 11:43
Formal class 'jobjRef' [package "rJava"] with 2 slots ..@ jobj :<externalptr> ..@ jclass: chr "org/apache/poi/xssf/usermodel/XSSFWorkbook"
– Alvi
Nov 9 at 11:43
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I had the same issue with this. I did the followings and it fixed the issue. Maybe it can solve yours.
- Close R or RStudio.
- Make sure that your current working directory does not have any other file or folder. In other words, the path in which you would like to save the xlsx is empty prior to running createWorkbook(). If you have already saved any file in there, just copy and paste it somewhere else.
- Run your code again from the beginning.
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I had the same issue with this. I did the followings and it fixed the issue. Maybe it can solve yours.
- Close R or RStudio.
- Make sure that your current working directory does not have any other file or folder. In other words, the path in which you would like to save the xlsx is empty prior to running createWorkbook(). If you have already saved any file in there, just copy and paste it somewhere else.
- Run your code again from the beginning.
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
add a comment |
up vote
1
down vote
accepted
I had the same issue with this. I did the followings and it fixed the issue. Maybe it can solve yours.
- Close R or RStudio.
- Make sure that your current working directory does not have any other file or folder. In other words, the path in which you would like to save the xlsx is empty prior to running createWorkbook(). If you have already saved any file in there, just copy and paste it somewhere else.
- Run your code again from the beginning.
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I had the same issue with this. I did the followings and it fixed the issue. Maybe it can solve yours.
- Close R or RStudio.
- Make sure that your current working directory does not have any other file or folder. In other words, the path in which you would like to save the xlsx is empty prior to running createWorkbook(). If you have already saved any file in there, just copy and paste it somewhere else.
- Run your code again from the beginning.
I had the same issue with this. I did the followings and it fixed the issue. Maybe it can solve yours.
- Close R or RStudio.
- Make sure that your current working directory does not have any other file or folder. In other words, the path in which you would like to save the xlsx is empty prior to running createWorkbook(). If you have already saved any file in there, just copy and paste it somewhere else.
- Run your code again from the beginning.
answered Nov 9 at 21:57
R User Scientist
415
415
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
add a comment |
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
I did it, but get the error again.
– Alvi
Nov 10 at 8:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221051%2ferror-in-addworksheetwb-sheet1-first-argument-must-be-a-workbook%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The code you have shared doesn't throw any error in my case. The error message you have shared indicates that the workbook
wb
was not created. Maybe you skipped executing line 1 of the code.– Rage
Nov 9 at 7:13
I have not skipped that line. Actually, this was working well but recently failed. but don't know why?
– Alvi
Nov 9 at 7:43
What does
str(wb)
show?– user2554330
Nov 9 at 10:19
Formal class 'jobjRef' [package "rJava"] with 2 slots ..@ jobj :<externalptr> ..@ jclass: chr "org/apache/poi/xssf/usermodel/XSSFWorkbook"
– Alvi
Nov 9 at 11:43