DataTables导出到Excel下载zip文件 [英] DataTables Export to Excel downloading a zip file

查看:68
本文介绍了DataTables导出到Excel下载zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Buttons扩展在jQuery DataTables上实现导出按钮。除了导出到Excel按钮之外,我的所有按钮都工作。

I am implementing export buttons on jQuery DataTables using the Buttons extension. I have all the buttons working except for the export to Excel button.

包括以下所有脚本:

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/datatables/media/js/jquery.dataTables.js"></script>
<script src="bower_components/datatables/media/js/dataTables.bootstrap.js"></script>
<script src="bower_components/datatables-buttons/js/dataTables.buttons.js"></script>
<script src="bower_components/datatables-buttons/js/buttons.html5.js"></script>
<script src="bower_components/datatables-buttons/js/buttons.print.js"></script>
<script src="bower_components/datatables-buttons/js/buttons.bootstrap.js"></script>
<script src="bower_components/jszip/dist/jszip.js"></script>
<script src="bower_components/pdfmake/build/pdfmake.js"></script>
<script src="bower_components/pdfmake/build/vfs_fonts.js"></script>

然后我创建按钮并将它们附加到div:

Then I create the buttons and append them to a div:

// Create and render buttons
new $.fn.dataTable.Buttons( table, {
    buttons: ['copyHtml5', 'csvHtml5', 'excelHtml5', 'pdfHtml5', 'print']
})
table.buttons().container().appendTo($('.header-right'), self);

单击Excel按钮时,我的应用程序会下载xlsx.zip文件。为什么不下载.xlsx文件?

When clicking on the Excel button, my app downloads a xlsx.zip file. Why is it not downloading a ".xlsx" file?

我也尝试通过手动添加扩展来扩展按钮,但是我设置的扩展属性结束了最多为extension-name.zip。

I've also tried to extend the button by manually adding the extension but whatever I set to the extension property ends up as "extension-name.zip".

new $.fn.dataTable.Buttons( table, {
    buttons: [
        {
            extend: 'excelHtml5',
            extension: '.xlsx'
        }
    ]
 })


推荐答案

设置Title属性对我有用。

Setting the Title property worked for me.

以下使用.xlsx文件扩展名导出

The following exported with the .xlsx file extension

 buttons: [{
            extend: 'excelHtml5',
            title: 'Location Report' 
            }
          ],.....etc

未设置标题时,使用.zip文件扩展名导出的文件

When the title was not set, the file exported with the .zip file extension

 buttons: [{
            extend: 'excelHtml5',
            title: '' 
            }
          ],.....etc

这篇关于DataTables导出到Excel下载zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆