Javascript Table Export To Excel
I have found a way to export HTML tables to Excel, but I'm having problem with exporting JavaScript table export from website to excel. Please help me to find a way, to export this
Solution 1:
I found the answer myself.
The javascript function got its information from page:
http://www.jalgpall.ee/db/getplayergame.php?reg=ellermaasoft&player=28469&&sid=0.1&year=2012&page=0
and from this page I can export data straight to Excel, using Excel->Data->Export Data from Web
Solution 2:
Here is the code using Kendo UI Library :
functionsave_table_to_excel(id_of_table){
//get the tablevar table = $(id_of_table)[0];
    var workbook = {
        creator: "The programmer",
        sheets:[]
    };
//build the headervar columns=[];
    var cells=[];
    var row = table.rows[0];
    for (var j = 0, col; col = row.cells[j]; j++) {
        columns.push({ autoWidth: true });
        cells.push({ value: col.textContent })
    }
    excelRows =[
        {
            cells: cells
        }
    ];
//put the contentfor (var i = 1, row; row = table.rows[i]; i++) {
        cells=[];
        for (var j = 0, col; col = row.cells[j]; j++) {
            cells.push({ value: col.textContent })
        }
        excelRows.push({ cells: cells });
    }
//export to Excel
    sheet={
        title: id_of_table,
        columns: columns,
        freezePane: { colSplit: 2, rowSplit: 1 },
//      filter: { from: 0, to: 7 },
    };
    sheet.rows=excelRows;
    workbook.sheets.push(sheet);
    var dataURL = new kendo.ooxml.Workbook(workbook).toDataURL();
    // save the workbook
    kendo.saveAs({
        dataURI: dataURL,
        fileName: kendo.toString(newDate(), 'yyyy.MM.dd')+id_of_table+".xlsx"
    });
}
Solution 3:
You can also use the package fs-browsers. It has nice and easy export method for xls files. It goes like this:
import { exportFile, EXCEL_FILE } from'fs-browsers';
const result_table = [
        ["1", "January", "2016"],
        ["2", "February", "2016"],
        ["3", "March", "2016"],
        ["4", "April", "2016"],
    ];
const headings = ["Day", "Month", "Year"];
exportFile(result_table, { type: EXCEL_FILE, headings: headings });
Post a Comment for "Javascript Table Export To Excel"