Excel formula not updating after writing new data through R openxlsx package

56 Views Asked by At

I'm trying to automate some processes in Excel using R language and openxlsx library.

When I write new data to a cell (which works fine) that is a reference to a formula in other cells, those cells with formulas do not update their values, even after I save the file and try to read it again.

Is there any workaround to fix this behavior?

Code and workbook follow.

library(openxlsx)

getwd()
setwd('Downloads')

wb = loadWorkbook('Plan.xlsx')
wb

activeSheet(wb) = 2
activeSheet(wb)

writeData(wb, sheet=2, startCol = 2, startRow = 2, x = 'p2')
print(read.xlsx(wb, sheet=2, startRow = 2, cols = c(3,4,5), colNames = F))
saveWorkbook(wb, file = 'Plan.xlsx', overwrite = T, returnValue = T)

Plan1 Plan2

Tried to:

  1. save the file;
  2. close it;
  3. read it again;

expecting to have the cells updated with their new values.

0

There are 0 best solutions below