r - Openxlsx:如何将工作表保存到文件?
问题描述
我正在尝试学习openxlsx
R 中的包。我可以使用loadWorkbook()
. 到目前为止,一切都很好。当我尝试使用 将此工作簿保存到磁盘saveWorkbook()
时,出现以下错误消息:
Error in write_worksheet_xml_2(prior = prior, post = post, sheet_data = ws$sheet_data, :
CHAR() can only be applied to a 'CHARSXP', not a 'NULL'
当我使用原始名称(和overwrite = TRUE
选项)时也会发生同样的情况,尝试保存到一个新文件,无论是否编辑文件内容。
我上线了
- macOS 10.14.6,
- R 4.0.2,
- Rstudio 1.3.1093,和
- openxlsx 4.2.3。
这里有人可以帮我找到解决方案吗?我无法从错误消息中看出从哪里开始寻找解决方案。搜索网络并没有给出有用的结果。
解决方案
I came across your question because I had the same problem.
After a lot of trial and error, I realised that this problem could be traced back to the fact that various rows in my excel-file were grouped (using excels group-function). After deleting these groupings, adding a sheet to an existing workbook with the regular procedure worked without any problems:
wb <- loadWorkbook("myfile.xlsx")
writeData(wb, sheet = "mysheet", mydataframe)
saveWorkbook(wb, "myfile.xlsx", overwrite = T)
I hope this answer can help someone who's also facing this problem :)
推荐阅读
- elasticsearch - 当我在 Elastic Search 中重新索引时,我无法使用包含破折号的新名称重命名字段
- python - Python 异常 ImportError - 尝试使用不知道父包的相对导入
- python - 如何使用 Python 脚本将 HTML 批量转换为 Markdown
- azure - Azure 数据工厂 - 设置 blob 容器的元数据以及“复制”活动
- amazon-web-services - 如何将 PATH 导出到“sam build”命令?
- flutter - 是否有任何 SDK 在 Flutter 中我们可以在同一屏幕上看到七个直播流媒体?
- hibernate - Hibernate:添加强制谓词
- javascript - API 仅在我开始输入后呈现(Firebase)
- java - Java中的多维数组到JSON(和返回)
- visual-studio-code - VSCode API 中是否有可以检查语言服务器是否可用于给定语言的命令?