首页 > 解决方案 > R:如何使用 XLConnect 的 setCellFormula 函数编写非英语的 excel 公式?

问题描述

当我使用 XLConnect 和 setCellFormula 将德语 excel 公式写入工作簿时,相应的单元格显示公式中未解析名称的错误(显示为“#NAME?”)。当我打开工作簿时,输入单元格并使用 ENTER 键将其保留,公式将起作用。

我的代码有问题吗?所有这一切都发生在 windows7 和 Excel 2010 上。

library(XLConnect)
out_wb <- loadWorkbook("test.xlsx", create = TRUE)

createSheet(out_wb, name = "test_data")
writeWorksheet(out_wb, "test_data", header = FALSE, data = 1:50)

createSheet(out_wb, name = "test_calc")

# german formula - cells gives '#NAME?'-error. Result not displayed until you enter the cell and leave it with ENTER
setCellFormula(out_wb, sheet = "test_calc", row = 1, col = 1, formula = "SUMME(test_data!A2:A10)")

# english formula - works as expected 
setCellFormula(out_wb, sheet = "test_calc", row = 2, col = 1, formula = "SUM(test_data!A2:A10)")

# recalculation does not solve the issue
setForceFormulaRecalculation(out_wb, sheet = "test_calc", TRUE)

saveWorkbook(out_wb)

手动翻译公式不是一种选择,因为公式很多并且来自文本文件。任何帮助表示赞赏。

标签: rexcelxlconnect

解决方案


推荐阅读