JQuery数据表;更改HTML5 Excel按钮导出中的单元格内容

时间:2016-05-28 17:56:16

标签: datatables

我正在使用JQuery Datatable HTML5导出按钮。我正在进行Excel导出,但我希望将包含图像的单元格导出为" 1"而不是图像的html标签。我怎样才能做到这一点。请参阅下面的尝试

HTML

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>First Aider</th>
            <th>Fire Warden</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>François Hollande</td>
            <td><img src='http://www.roastthatmeat.co.uk/Images/flag_red.png' /></td>
            <td></td>
        </tr>
        <tr>
            <td>David Cameron</td>
            <td><img src='http://www.roastthatmeat.co.uk/Images/flag_red.png' /></td>
            <td><img src='http://www.roastthatmeat.co.uk/Images/flag_yellow.png' /></td>
        </tr>
        <tr>
            <td>Angela Merkel</td>
            <td></td>
            <td><img src='http://www.roastthatmeat.co.uk/Images/flag_yellow.png' /></td>
        </tr>
        <tr>
            <td>Barack Obama</td>
            <td></td>
            <td><img src='http://www.roastthatmeat.co.uk/Images/flag_yellow.png' /></td>
        </tr>
</tbody>

的Javascript

$(document).ready(function() {
$('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [{
        extend: 'excelHtml5',
        customize: function(xlsx) {
            var sheet = xlsx.xl.worksheets['sheet1.xml'];

            $('row c[r^="B"]', sheet).each( function () {
                if ( $('is t', this).html() == "<img src='http://www.roastthatmeat.co.uk/Images/flag_red.png' />" ) {
                    $('is t', this).text(1);
                }else
                {
                 $('is t', this).text(0);
                }
            });
            $('row c[r^="C"]', sheet).each( function () {
                if ( $('is t', this).html() == "<img src='http://www.roastthatmeat.co.uk/Images/flag_yellow.png' />" ) {
                    $('is t', this).text(1);
                }else
                {
                 $('is t', this).text(0);
                }
            });
        }
    }]
});

});

Please see fiddle

0 个答案:

没有答案