【问题标题】:Updating excel through xlsx and printing pdf through libreoffice. But content does not get updated通过 xlsx 更新 excel 并通过 libreoffice 打印 pdf。但是内容没有更新
【发布时间】:2018-04-24 09:00:32
【问题描述】:

我正在使用 R 中的 xlsx 包更新一个 excel 模板,然后使用 R 中的系统命令将其编写为 pdf。在系统命令中我使用的是 libreoffice-calc(类似于 excel)。但是如果我打开它,我使用 R 所做的更新会在文件中更新。但pdf不打印。

在本例中,chk.xlsx 是一个带有两个选项卡的 Excel 工作表,需要打印第二个选项卡。

library(xlsx)
wb<-loadWorkbook("chk.xlsx")
sheets <- getSheets(wb)
sheet2 <- sheets[["Sheet1"]]
a=c(1:5)
b=c(6:10)
x <- as.data.frame(cbind(a,b))
addDataFrame(x, sheet2, startRow=2, startColumn=1,col.names=F, row.names=F)

wb$setForceFormulaRecalculation(TRUE)
#setForceFormulaRecalculation(wb,"data",TRUE)

saveWorkbook(wb, "chk.xlsx")
system(paste0("libreoffice --convert-to pdf chk.xlsx")) # empty pdf
#system(paste0("libreoffice --headless --convert-to pdf chk.xlsx")) # empty pdf
#system(paste0("libreoffice --headless --invisible --convert-to pdf chk.xlsx")) # empty pdf

即使我在运行 R 脚本后尝试从命令行(不是 Rstudio/R 控制台的终端)运行它,我也没有得到更新的工作表的打印。

 libreoffice --headless --convert-to pdf chk.xlsx

【问题讨论】:

    标签: r pdf-generation libreoffice-calc


    【解决方案1】:

    终于解决了。

    Excel 中的公式不会在 LibreOffice 中自动更新。所以,你将不得不这样做。

    工具 > 选项 > LibreOfficeCalc > 公式 > 文件加载时重新计算

    将此设置为始终重新计算。 (虽然最好通过命令行设置)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多