Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...