Tuesday 15 July 2014

r - editing particular cells of an Excel sheet -



r - editing particular cells of an Excel sheet -

i have excel workbook of want edit/fill particular cells using r, without changing of formatting.

so far i've tried xlconnect bundle , seems i'm looking for, didn't find way it.

my straightforward approach problem:

wb <- loadworkbook("file1.xls") data1 <- readworksheet(wb, "sheet1", header=true) ## adding value particular cell: data1[11,12] <- 3.2 ## rewriting old data: writeworksheet(wb, data1, "sheet1") saveworkbook(wb, "new_file1.xls")

however, way new workbook loses of previous formatting (merged cells, formulas, etc).

is there way alter values in of cells without losing of formatting of remaining sheet?

here illustration using r automate excel.

library(rdcomclient) xlapp <- comcreate("excel.application") wb <- xlapp[["workbooks"]]$open("file.1.xls") sheet <- wb$worksheets("sheet1") # alter value of single cell cell <- sheet$cells(11,12) cell[["value"]] <- 3.1 # alter value of range range <- sheet$range("a1:f1") range[["value"]] <- paste("col",1:6,sep="-") wb$save() # save workbook wb$saveas("new.file.xls") # save new workbook xlapp$quit() # close excel

r excel xlconnect

No comments:

Post a Comment