You cannot do it with the current version of the package. It is implemented in the next version of the java POI library 3.8 (still in beta). But you can download it and drop the 3.8 jars into the xlsxjars package in the java/ folder on top of the 3.7 ones.
Then before you save your spreadsheet do a
wb$setForceFormulaRecalculation(TRUE)
See http://poi.apache.org/spreadsheet/eval.html for more details.
Adrian
I’m waiting for the 3.8 version to be released before I add it to the R package.
require(xlsx)
wb <- createWorkbook()
sheet1 <- createSheet(wb, "Sheet1")
rows <- createRow(sheet1, 1:10) # 10 rows
cells <- createCell(rows, colIndex=1:8) # 8 columns
for( r in 1:9)
setCellValue( cells[[ r, 1]], r)
cell <- cells[[ 10, 1]]
cell$setCellFormula( 'SUM(A1:A9)' )
evaluator <- wb$getCreationHelper()$createFormulaEvaluator()
#evaluator$evaluateInCell( cells[[10,1]] ) # replaces the formula with the value
evaluator$evaluateFormulaCell( cell ) # keeps formula in cell returns the cell type ...
cell$getNumericCellValue()
saveWorkbook( wb, file = 'out.xlsx' )
--
You received this message because you are subscribed to the Google Groups "R-package-xlsx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-package-xls...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.