Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

export to csv - How do I insert Iamge into Excel Cell while exporting it through javascript?

I have a function that takes all the data from a specific table name and export it to the CSV files. the javascript code for exporting into excel is:-

(function () {
    "use strict";

    window.SR = window.SR || {};
    window.SR.TableExport = {
        exportCsv: function (table, filename) {
            var csvRows = [];
            var tableRows = table.querySelectorAll("tr");

            for (var row_ix = 0; row_ix < tableRows.length; row_ix++) {
                var csvColumns = [];
                var tableCells = tableRows[row_ix].querySelectorAll("td, th");

                for (var col_ix = 0; col_ix < tableCells.length; col_ix++) {
                    var text = tableCells[col_ix].innerText;
                    var span = tableCells[col_ix].getAttribute("colspan") || 1;
                    if (text.match(/^d+$/)) {
                        csvColumns.push(text);
                    } else {
                        csvColumns.push('"' + text + '"');
                    }

                    for (var extraColumns = 0; extraColumns < span - 1; extraColumns++) {
                        csvColumns.push('""');
                    }
                }

                csvRows.push(csvColumns.join(","));
            }

            var csv = csvRows.join("
");

            var csvBlob = new Blob([csv], { type: "text/csv" });

            var downloadLink = document.createElement("a");
            downloadLink.download = filename;
            downloadLink.href = window.URL.createObjectURL(csvBlob);
            downloadLink.style.display = "none";
            document.body.appendChild(downloadLink);
            downloadLink.click();
        }
    };
})();

now I need to add the company logo/image at the top while exporting it to the excel/csv files. I tried by adding the image on the top of the table, the image appeared in the view page but while exporting it to the excel the cell was blank. How can I do it?

question from:https://stackoverflow.com/questions/66045786/how-do-i-insert-iamge-into-excel-cell-while-exporting-it-through-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...