ExcelHtml5 export - setting title to null causes Excel to repair file

ExcelHtml5 export - setting title to null causes Excel to repair file

sdroulerssdroulers Posts: 43Questions: 14Answers: 0

Hi,

I'm facing an issue with the Excel export that causes Excel to repair the file.

In my Excel, I don't want the title line to appear.

I use the following setting for my button:

 buttons: ['copyHtml5', {
            extend: 'excelHtml5',
            text: 'Sauver en tant que fichier Excel',
            filename: function() {
                var date_edition = moment().format("YYYY-MM-DD HH[h]mm")
                var selected_machine_name = $("#output_select_machine select option:selected").text()
                return date_edition + ' - ' + selected_machine_name
            },
            sheetName: 'Output logiciel complet',
            title : null
        }]

If I set title to another value (a string for example), it works fine.

Thanks,

Sébastien

This question has an accepted answers - jump to answer

Answers

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0

    Just an update : it appears that if I use an empty string it doesn't work either.

    title : ''
    

    While other strings work:

    title : 'Test'
    

    I use the following version 1.4.2 for the buttons:

    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.4.2/js/buttons.html5.min.js"></script>
    
  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0
    edited November 2017

    Looks like it works using version 1.3.1 .

    Still reading the docs to see where my code that causes this problem.

    EDIT : logical since title export has been introduced in 1.4.0 ...

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Could you try the nightly version where this has been resolved.

    Thanks,
    Allan

  • sdroulerssdroulers Posts: 43Questions: 14Answers: 0

    Works like a charm, thank you!

  • lukash229lukash229 Posts: 1Questions: 0Answers: 0

    Hi Dear, I 've just updated datatables library to v1.10.16 and I still have problem to export .xlsx file without title name. When I use title: null, MS Excel 2013 still has/wants to repair the document. I'd like to ask you to fix it in lates production datatables.net library, please. Thank you, Lukash

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    If you can link to a page showing the issue I would be happy to take a look and debug the issue.

    Allan

  • pbarneypbarney Posts: 2Questions: 0Answers: 1
    edited March 2018 Answer ✓

    EDIT: SOLUTION... I just realized that I was using buttons 1.4.1. When I switched to 1.5.1, everything works.

    I am having the same issue as lukash229 while using DataTables 1.10.16 . Unfortunately, the page is not accessible on the web yet (local dev server).

    When title is set to null, Excel produces the following error:

    "We found a problem with some content in 'filename.xlsx'. Do you want us to try to recover as much as we can?"

    If title is set to anything else, it works fine.

    Here is the relevant part of my code:

        results = $('#results').DataTable({
            buttons: [
                {name: 'copy',  extend: 'copy',  exportOptions: {columns: ':gt(0)', orthogonal: 'export'}, filename: title, title: null},
                {name: 'excel', extend: 'excel', exportOptions: {columns: ':gt(0)', orthogonal: 'export'}, filename: title, sheetName: 'Results', title: null},
                {name: 'csv',   extend: 'csv',   exportOptions: {columns: ':gt(0)', orthogonal: 'export'}, filename: title, title: null}
            ],
    
This discussion has been closed.