excel - How to delete data from a XLSX file while keeping formatting in R -


i have 3 xlsx files 7 sheets each. each morning have delete contents of each sheet prepare importing new data.

i want automate process using r. can excel macro, r script want (that way don't need wait longer macro enabled files way slower).

i want blank sheets while keeping sheetnames, , formatting (i have formatted cells text, , cells have particular widths). solutions using openxlsx package more appreciated.

edit:

the sheets contain 15 columns , @ max 200 rows. still non vectorized solutions bit slow.

this seems bit of hack, can write empty string each cell in use , save resulting workbook.

library(openxlsx) wb = loadworkbook("test.xlsx")  for(ss in 1:length(wb$worksheets)) {     rows = wb$worksheets[[ss]]$sheet_data$rows     cols = wb$worksheets[[ss]]$sheet_data$cols      for(i in 1:length(rows)) {         writedata(wb,ss,"",  startcol = cols[i], startrow = rows[i])     } } saveworkbook(wb, "test2.xlsx", overwrite = true) 

however, why can't make empty spreadsheet once template , make copy every time need use it?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -