将表格数据导出到CSV问题

时间:2019-11-09 08:05:41

标签: javascript jquery html-table datatable export-to-csv

我尝试将选中的行导出为CSV 我已经使用复选框检查了表格行 并在csv中成功导出数据,但表数据的第一行在csv文件中无法正常显示

enter image description here

波纹管代码

function myFunction(){

        //Reference the Table.
       // var grid = document.getElementById('tableInc');
        //Reference the CheckBoxes in Table.
        var checkBoxes = document.getElementsByClassName('getChecked');
        var csv = "Id , NAme , IsActive , Salesdesc , Frenchdesc \n";
        //Loop through the CheckBoxes.
        for (var i = 0; i < checkBoxes.length; i++) {
            if (checkBoxes[i].checked) {
                var row = checkBoxes[i].parentNode.parentNode;
                csv += row.cells[1].innerHTML;
                csv += " , " + row.cells[2].innerHTML;
                csv += " , " + row.cells[3].innerHTML;
                csv += " , " + row.cells[4].innerHTML;
                csv += " , " + row.cells[5].innerHTML;
                csv += "\n";
            }
        }

        $("#csv").text(csv);
        window.URL = window.URL || window.webkiURL;
        var blob = new Blob([csv]);
        var blobURL = window.URL.createObjectURL(blob);
        $("#downloadLink").html("");
        $("<a></a>").
        attr("href", blobURL).
        attr("download", "data.csv").
        text("Download Data").
        appendTo('#downloadLink');
    }

在所有数据格式正确后,csv文件中仅第一行附加问题 我找不到问题,请帮助我进行调试 谢谢

0 个答案:

没有答案