首页 > 解决方案 > Openxlsx:如何将工作表保存到文件?

问题描述

我正在尝试学习openxlsxR 中的包。我可以使用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选项)时也会发生同样的情况,尝试保存到一个新文件,无论是否编辑文件内容。

我上线了

这里有人可以帮我找到解决方案吗?我无法从错误消息中看出从哪里开始寻找解决方案。搜索网络并没有给出有用的结果。

标签: ropenxlsx

解决方案


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 :)


推荐阅读