Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export hyperlinks to Excel. #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

amh-mw
Copy link

@amh-mw amh-mw commented Sep 25, 2019

Inspired by https://stackoverflow.com/questions/40243616/jquery-datatables-export-to-excelhtml5-hyperlink-issue/49146977

This patch extends the special formatting capability of the Excel exporter to detect the "=FUNCTION(...)" signature customary in Excel, specifically for hyperlinks.

This PR does not attempt to solve the broader hyperlink rendering issue, though along the lines of the fourth example at https://datatables.net/reference/option/columns.render#Examples, a user could add a renderer for a custom 'excel' orthogonal:

$('#example').dataTable( {
  columnDefs: [ {
    render: {
      display: function ( data, type, row, meta ) {
        return '<a href="'+data+'">Download</a>';
      },
      excel: function ( data, type, row, meta ) {
        return '=HYPERLINK("'+data+'",'"Download"')';
      },
    }
  }]
});

then configure the export button to use it:

$('#report').dataTable({
  buttons: [{
    extend: 'excel',
    exportOptions: {
      orthogonal: 'excel',
    },
  }]
});

@DataTables
Copy link
Collaborator

That's awesome - thank you for this.

I'm not going to pull it in immediately as I'd like to sync this up with the same ability in pdf export, and I'd like to think about the implementation a little, but I think others will find this really useful.

@amh-mw
Copy link
Author

amh-mw commented Sep 26, 2019

Absolutely. I still need to copy this logic into buttons.flash.js, write some tests, and as I woke up this morning I remembered that the "t" attribute needs to be set to "str". Definitely some polishing to do yet, but I wanted to get the core up for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants