5

In my shiny app, I'm using:

# server.R
  output$out_table = DT::renderDataTable(
    func_to_creat_dataframe(),
    rownames= FALSE,
    extensions = c('Buttons'),
    options = list(
      pageLength = 96,
      lengthMenu = c(96, 384, 1536),
      dom = 'Blfrtip',
      buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
    )
  )
# UI.R
DT::dataTableOutput('out_table')

...and when I use the "Excel" button to export the table, the exported table has a "title" row directly above the header row. This title row consists of one merged cell that spans across the entire header. How do I remove this? This title row interferes with downstream processing of the file, and it's completely unnecessary, so I don't see why it appears to be default for the datatable file export buttons.

1 Answer 1

4

Try that:

DT::datatable(
  iris,
  rownames= FALSE,
  extensions = c('Buttons'),
  options = list(
    pageLength = 96,
    lengthMenu = c(96, 384, 1536),
    dom = 'Blfrtip',
    buttons = list(
      'copy', 
      'csv', 
      list(extend = 'excel', title = NULL), 
      'pdf', 
      'print'
    )
  )
)
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the suggestion! It works except, at least for Mac 2011 Excel, I get an error/warning stating: Excel could not open the document because some of the content is unreadable. Do you want to open and repair this workbook? Clicking Open and repair works. The excel repair log file shows: </summary><repairedParts summary="Following is a list of repairs:"><repairedPart xml:space="preserve">Repaired Part: /xl/worksheets/sheet1.xml part. </repairedPart></repairedParts></recoveryLog>
Doesn't work on Windows 2013 Excel either. I get the same issue as above
@Kevin And this works when there is a title? Strange;
@StéphaneLaurent, didn't try. I just don't have title as an input at all. Adding title = NULL creates an unrepairable workbook though
@Kevin This bug has been encountered in the past. DT uses the buttons extension version 1.5.2, it is strange that this bug still occurs.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.