I have a query related to the xlsx package in R. I know how to use most of the functions in the package and have not yet encountered any problems. First I will show my code, and then I will ask my question.
#Code-Section1: library(xlsx) data1<-iris data1<-data1[,c(5,1:4)] wb <- createWorkbook() sheet1 <- createSheet(wb, sheetName="Sheet1") addDataFrame(data1, sheet1, startRow=1, startColumn=1,row.names=FALSE) saveWorkbook(wb, file="test.xlsx") rm(data1);rm(sheet1);rm(wb)
This part simply takes the aperture dataset and places it on a sheet called Sheet1, in an Excel table called test.xlsx. Now in excel, I decided to add additional content to the distribution sheet by adding a common row, so the last two rows of the Excel spreadsheet:
virginica 5.9 3.0 5.1 1.8 876.5 458.6 563.7 179.9
Another thing I'm doing is adding four more columns to the spreadsheet containing the percentage of each figure from the summary rows. Then I want to load test.xlsx into the workbook R. I define a new data frame called temp, with some random normal values. My intention is to update the numbers in the test.xlsx file so that the resulting row values ββand percentages subsequently change. The last two lines of the updated spreadsheet should be something else, depending on the output of the rnorm values ββ(150,5,1). I save the data frame to a new table called testa.xlsx. The values ββare updated, but for some reason, the total row values ββand percentages remain unchanged, although their cell values, for example, are still "= sum (b2: b151)" or "= b2 / b $ 152".
#Code-Section2: temp <- data.frame(Sepal.Length=rnorm(150,5,1), Sepal.Width=rnorm(150,5,1), Petal.Length=rnorm(150,5,1), Petal.Width=rnorm(150,5,1)) wb<-loadWorkbook("test.xlsx") f<-getSheets(wb)[[1]] addDataFrame(temp, sheet=f, startRow=2, startColumn=2,row.names=FALSE,col.names=FALSE) saveWorkbook(wb, file="testa.xlsx")
So my question is how to load the workbook, update the numbers so that cells that have formulas in them will be subsequently updated and then saved in a new excel file. Maybe I can do it differently, but this will require additional steps, which I do not mind, but just updating the numbers so that other cells change, it would be so convenient. Again, as in every post I make, I ask you to forgive any grammatical errors and feel free to change any of these messages if you think it is necessary.