R : Error in replacing data in existing excel report

时间:2018-12-03 12:51:15

标签: java r memory report xlconnect

I am trying to replace the data in a few sheets of an existing excel workbook (there are several sheets with formulae in it which remain untouched). I am using the package XLConnect for the same. The idea is to read an existing workbook , clear the data in the required sheets and then write new dataframes in to them. After this, the file is saved both as the initial version as well as another version with the date. However the syntax saveWorkbook is taking a long time to execute and in the end is throwing up the following error Error: OutOfMemoryError (Java): Java heap space

I installed rJava and ran the following as well: options(java.parameters = "-Xmx2048m")

Is there any alternate way to do it?

Following is the code:

xlWb <- loadWorkbook("C:\\\\Users\\z003b1d\\Desktop\\Drop_Data_DB2_Template.xlsx")
wbnames <- as.vector(getSheets(xlWb)) ##sheetNames

clears the data in the existing template

clearSheet(xlWb, sheet= c("Dept Var to Prior Day-FC RDC",           "Dept Var to Prior Day-BP UDC",    "Dept Var to Prior Day-BP",         "Dept Var to Prior Day - FC UDC",               "Drop_Data_DB2", "Forecasts"))

rewrites the data in the required sheets

writeWorksheet(xlWb,list(i1= rdc_finalsorted, i2= udc_finalsorted, i3= rdc_bpr_finalsorted, i4= udc_fcs_finalsorted, i5= data, i6= forecast)  , sheet= c("Dept Var to Prior Day-FC RDC",     "Dept Var to Prior Day-BP UDC",            "Dept Var to Prior Day-BP",         "Dept Var to Prior Day - FC UDC",    "Drop_Data_DB2", "Forecasts"), startRow =1, startCol =1,  header= T, rownames = NULL)

saves the workbook

 saveWorkbook(xlWb,"C:\\\\Users\\z003b1d\\Desktop\\Drop_Data_DB2_Template.xlsx")

creates a version with today's date

saveWorkbook(xlWb, paste0("C:\\\\Users\\z003b1d\\Desktop\\Drop_Data_DB2_",Sys.Date(),".xlsx"))

0 个答案:

没有答案