In xlsx I had the possibility to append the new data on the bottom.
Does openxlsx have a similar function?
As a different solution I had to create a workbook for each data frame and copy paste it in the sheet.It does work till the 5 th loop of the second forloop. Then it shows an error,
I would rather just put all values in one Sheet and append the new values on the bottom (with a header that we are now in ff 02,
Can anyone help?
Here is my code:
for (ff in 1:12) {
a= sprintf("Actuals_predict_r_%02d_hwa", ff)
addWorksheet(wb,a)
if ( ff==1) {
writeData (wb,a, Actuals_predict_r_01_hwa)}
if ( ff==2) {
writeData (wb,a, Actuals_predict_r_02_hwa)}
if ( ff==3) {
writeData (wb,a, Actuals_predict_r_03_hwa)}
if ( ff==4) {
writeData (wb,a, Actuals_predict_r_04_hwa)}
if ( ff==5) {
writeData (wb,a, Actuals_predict_r_05_hwa)}
if ( ff==6) {
writeData (wb,a, Actuals_predict_r_06_hwa)}
if ( ff==7) {
writeData (wb,a, Actuals_predict_r_07_hwa)}
if ( ff==8) {
writeData (wb,a, Actuals_predict_r_08_hwa)}
if ( ff==9) {
writeData (wb,a, Actuals_predict_r_09_hwa)}
if ( ff==10) {
writeData (wb,a, Actuals_predict_r_10_hwa)}
if ( ff==11) {
writeData (wb,a, Actuals_predict_r_11_hwa)}
if ( ff==12) {
writeData (wb,a, Actuals_predict_r_12_hwa)}
}
for (ff in 1:12) {
b= sprintf("Actuals_predict_r_%02d_ets", ff)
addWorksheet(wb,b)
if ( ff==1) {
writeData (wb, b, Actuals_predict_r_01_ets)}
if ( ff==2) {
writeData (wb, b, Actuals_predict_r_02_ets)}
if ( ff==3) {
writeData (wb, b, Actuals_predict_r_03_ets)}
if ( ff==4) {
writeData (wb, b, Actuals_predict_r_04_ets)}
if ( ff==5) {
writeData (wb, b, Actuals_predict_r_05_ets)}
if ( ff==6) {
writeData (wb, b, Actuals_predict_r_06_ets)}
if ( ff==7) {
writeData (wb, b, Actuals_predict_r_07_ets)}
if ( ff==8) {
writeData (wb, b, Actuals_predict_r_08_ets)}
if ( ff==9) {
writeData (wb, b, Actuals_predict_r_09_ets)}
if ( ff==10) {
writeData (wb, b, Actuals_predict_r_10_ets)}
if ( ff==11) {
writeData (wb, b, Actuals_predict_r_11_ets)}
if ( ff==12) {
writeData (wb, b, Actuals_predict_r_12_ets)}
}
Save workbook to working directory
saveWorkbook(wb, file = "Actuals_forecast.xlsx", overwrite = TRUE)