title: R Shiny datatable extension buttons to download complete excel file with format
body: <p>I have created the following app in R shiny with two download options. One is a conventional downloadhandler option
  The second is using An R datatable button extension The App is structured as follows</p>
  <pre><code>library(shiny)
  library(openxlsx)
  library(readxl)
  library(DT)
  
  ui &lt;- fluidPage(   
  titlePanel(&quot;Writer App&quot;),
  sidebarLayout(sidebarPanel(fileInput(inputId = &quot;file&quot;, label = &quot;Read File Here&quot;, accept = 
   c(&quot;.xlsx&quot;)), downloadLink(&quot;downloadData&quot;, &quot;Download&quot;)), 
              mainPanel(DTOutput(outputId = &quot;table1&quot;))))
  
  
  
   server &lt;- function(input, output) {
   datasetInput &lt;- reactive({
   infile&lt;- input$file
   if (is.null(infile))
    return(NULL)   
   #READ .XLSX AND .CSV FILES
   if(grepl(infile$datapath, pattern = &quot;.xlsx&quot; )){data=read_excel(infile$datapath)} else 
    if(grepl(infile$datapath , pattern = &quot;.csv&quot; )){data=read.csv(infile$datapath )}
  
   #RENAME DATAFRAME WITH UNDERSCORES
   names(data)&lt;-gsub(pattern = &quot; &quot;, replacement = &quot;_&quot;, x =  names(data))
   return(data) 
  })
  
  output$table1 &lt;- renderDT({    
  
   datasetInput&lt;-datasetInput()
    datatable(datasetInput,extensions = c('Buttons', 'Scroller'), 
            options = list(
              dom = 'tB',
              deferRender = TRUE,
              scrollY = 400,
              scroller = TRUE,
              buttons = list(list(extend = 'excel'))) )
  
  
  
  
  
  })
  
  
     output$downloadData &lt;- downloadHandler(
     filename = function() {
     paste(&quot;data-&quot;, Sys.Date(), &quot;.xlsx&quot;, sep=&quot;&quot;)},
     content = function(file) {
     tf&lt;-tempdir()
     Files=list.files(path=tf, pattern=&quot;.xlsx&quot;, recursive = TRUE)[1]    
     file.copy(from =paste0(tf, &quot;/&quot;,Files ), to= &quot;temp_1.xlsx&quot;)     
     wb2 &lt;- loadWorkbook(file = &quot;temp_1.xlsx&quot;)
     df_1&lt;-data.frame(&quot;DF&quot;= c(1:3))      
     addWorksheet(wb = wb2,sheetName =  &quot;Parameters1&quot;)
     writeData(wb2, &quot;Parameters1&quot;, df_1, startCol = 1, startRow = 2, rowNames = TRUE)
     saveWorkbook(wb2, file)
    })}
  
   shinyApp(ui = ui, server = server)
  </code></pre>
  <p>When we load an excel file, The download handler retains the excel shete with its format intact, appends a new sheet to the workbook and downloads the excel workbook with a new sheet. Is it possible to do the same with the download button below the datatable- retain the format of the original excel, add a new sheet and download.</p>
  <p>I request someone to guide me. I am unable to find a solution for this</p>