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

Categories

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

javascript - How to add watermark image while exporting the table into excel file?

I have written code in Html, javascript, and CSS to view a table and added a button to export the data and header of the table to CSV/excel files.

My 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();
        }
    };
})();

document.getElementById("exportAll").addEventListener("click", function () {
        window.SR.TableExport.exportCsv(_CommunityHealthScores,"Scores.csv");
});

Now I need to add a watermark image behind the table in CSV/excel files while exporting. How Can I do that? My working example for exporting without a watermark image

https://jsfiddle.net/saLv0jmr/

question from:https://stackoverflow.com/questions/66058246/how-to-add-watermark-image-while-exporting-the-table-into-excel-file

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...