Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to refresh an excel file from within R?

Tags:

r

excel

I have some excel file with simple formulas like =SUM(A1:A3).

I need to import the file into R, but before that I need to refresh the formulas. Is there a way to refresh the file from within R? There are good packages for importing the data in a R dataframe (eg. the R xslx package) but I need to refresh my formulas first.

Any suggestions? Thanks!

like image 622
ℕʘʘḆḽḘ Avatar asked Nov 25 '25 04:11

ℕʘʘḆḽḘ


1 Answers

You should be able to do this with RDCOMClient:

library(RDCOMClient)
ex = COMCreate("Excel.Application")
book = ex$Workbooks()$Open("my_file.xlsx")
book$Worksheets("Sheet1")$Calculate() # if you have many sheets you could loop through them or use apply functions based on their actual names
book$Save()
book$Close()

Here's another thread on the underlying VBA

like image 91
David Klotz Avatar answered Nov 26 '25 19:11

David Klotz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!