Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

export2excel with logo and header and many table on one click stackoverflow

 function exportToExcel() {
        var tab_text = "<tr bgcolor='#87AFC6'>";
        var textRange; var j = 0, rows = '';
        tab = document.getElementById('student-detail');
        tab_text = tab_text + tab.rows[0].innerHTML + "</tr>";
        var tableData = $('#student-detail').DataTable().rows().data();
        for (var i = 0; i < tableData.length; i++) {
            rows += '<tr>'
                + '<td>' + tableData[i].value1 + '</td>'
                + '<td>' + tableData[i].value2 + '</td>'
                + '<td>' + tableData[i].value3 + '</td>'
                + '<td>' + tableData[i].value4 + '</td>'
                + '<td>' + tableData[i].value5 + '</td>'
                + '<td>' + tableData[i].value6 + '</td>'
                + '<td>' + tableData[i].value7 + '</td>'
                + '<td>' +  tableData[i].value8 + '</td>'
                + '<td>' + tableData[i].value9 + '</td>'
                + '<td>' + tableData[i].value10 + '</td>'
                + '</tr>';
        }
        tab_text += rows;
        var data_type = 'data:application/vnd.ms-excel;base64,',
            template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table border="2px">{table}</table></body></html>',
            base64 = function (s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            },
            format = function (s, c) {
                return s.replace(/{(w+)}/g, function (m, p) {
                    return c[p];
                })
            }

        var ctx = {
            worksheet: "Sheet 1" || 'Worksheet',
            table: tab_text
        }
        document.getElementById("dlink").href = data_type + base64(format(template, ctx));
        document.getElementById("dlink").download = "StudentDetails.xls";
        document.getElementById("dlink").traget = "_blank";
        document.getElementById("dlink").click();
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: Dominosteine c# 
Csharp :: laravel get current url 
Html :: html grundgerüst 
Html :: opem link in new tab html 
Html :: html meta redirect 
Html :: import js in html 
Html :: ml5 cdn 
Html :: html starter code 
Html :: align eliment in center of row bootstrap 
Html :: rs logo html 
Html :: twig count array 
Html :: html disable drag image 
Html :: upload only image input tag 
Html :: notyf 
Html :: html input type file accept text and word files 
Html :: enctype= multipart/form-data 
Html :: What is the RPC URL for Binance smart chain? 
Html :: set icon website 
Html :: Hello World HTML Code Example 
Html :: html favicon 
Html :: html skype call 
Html :: visualizador de pdf html5 
Html :: html ö 
Html :: how to print hello world in html 
Html :: bootstrap 5 vertical align 
Html :: syntax for ngfor 
Html :: fa fa-home 
Html :: discernible name 
Html :: target blank html 
Html :: coreui text align center 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =