【问题标题】:openxlsx writeData() and saveWorkbook() create corrupted Excel fileopenxlsx writeData() 和 saveWorkbook() 创建损坏的 Excel 文件
【发布时间】:2021-11-30 20:21:04
【问题描述】:

当我使用openxlsx 保存数据框时,生成的文件最终被损坏。

library(openxlsx)

# Making dummy dataframe
Name <- c("Jon", "Bill", "Maria", "Ben", "Tina")
Age <- c(23, 41, 32, 58, 26)

df <- data.frame(Name, Age)

# Creating output file 
output_path <- "check_corruption.xlsx"
wb <- createWorkbook(output_path) 
addWorksheet(wb, "Sheet1")

# Write unformatted data
writeData(wb, sheet=1, df)

# Save fully formatted output
saveWorkbook(wb, output_path, overwrite=TRUE)

当我尝试打开 check_corruption.xlsx 时出现错误

“我们发现 'check_corruption.xlsx' 中的某些内容存在问题。执行 你想让我们尽可能多地恢复吗?”。

如果我修复文件,那么输出看起来很好,但我不明白是什么导致了问题。

【问题讨论】:

    标签: excel corruption openxlsx


    【解决方案1】:

    原来这是由于文件的输出路径中有一个“&”符号,openxlsx 不支持该符号。我打开了一个已解决的问题here,因此如果您遇到此问题,请将您的 openxlsx 安装更新到 github 的主分支。

    【讨论】:

      猜你喜欢
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 2019-05-01
      • 2017-03-29
      相关资源
      最近更新 更多