简体   繁体   English

XLConnect:保存工作簿更新错误

[英]XLConnect: saveworkbook update error

saveWorkbook() function in XLConnect saves the workbook and the changes and updated calculations are visible in the excel file but not on R (because it has a formula not accepted by the apache poi) saveWorkbook()函数保存工作簿,并且更改和更新的计算在excel文件中可见,但在R上不可见(因为它的公式未被apache poi接受)

However, to view the cell I save the file to disk and call it using another function. 但是,要查看单元格,我将文件保存到磁盘并使用其他功能调用它。 But when I call the same file again the calculated fields still show the old values. 但是,当我再次调用同一文件时,计算所得的字段仍显示旧值。 I don't want to save the excel file every time I make a change in the workbook. 我不想每次在工作簿中进行更改时都保存excel文件。

Would you know a workaround to be able to call the new values without manually saving excel? 您是否知道一种解决方法,可以在不手动保存excel的情况下调用新值?

Code - 代码-

options(java.parameters = "-Xmx1024m")
library(rJava)
library(XLConnect)
wb = loadWorkbook(file.choose(), create = TRUE)
readWorksheet(wb,16, region = 'D25:D26')
writeWorksheet(wb,-.45,sheet = 16,startRow = 25,startCol = 4)
setForceFormulaRecalculation(wb,sheet = 16, TRUE)
saveWorkbook(wb)
detach("package:XLConnect", unload=TRUE)
detach("package:XLConnectJars", unload=TRUE)
library(xlsx)
y = read.xlsx(file.choose(), sheetIndex = 16)

So the Excel file on the system shows the changes corresponding to the new -.45 value but when I read the file again, the calculated values are the old values and not the new ones. 因此,系统上的Excel文件显示了与新的-.45值相对应的更改,但是当我再次读取该文件时,计算出的值是旧值,而不是新值。 This gets fixed if I save the file manually. 如果我手动保存文件,此问题将得到解决。

I believe the command you are using is correct but maybe some small modifications would make this work. 我相信您使用的命令是正确的,但也许进行一些小的修改就可以使此工作正常。

I think you could try placing the needed calculations in a different sheet in excel and treat the data you inserted as a dependency for those calculations in the new sheet. 我认为您可以尝试将所需的计算放在excel的其他工作表中,并将插入的数据作为新工作表中这些计算的依赖项。

Then read it in as a fresh workbook and call the new sheet. 然后阅读它作为新的工作簿并调用新的工作表。 I think that will you the output you need. 我认为这将为您提供所需的输出。

setForceFormulaRecalculation(wb, sheet = "*", TRUE)

I would use this command to force all sheets to recalculate instead. 我将使用此命令来强制所有工作表重新计算。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM