0

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 table to Excel.

Page, from where i need the info:

www.jalgpall.ee/players.php?year=2012&team=84&player=28469&b=ML

Example of this page javascript table function:

JavaScript: function showPlayers() {
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp == null) {
        alert("Your browser dosen't support AJAX");
        return;
    }
    var url = "db/getplayergame.php?reg=ellermaasoft";
    url = url + "&player=" + document.getElementById("customers").value;
    url = url + "&sid=" + Math.random();
    url = url + "&year=" + document.getElementById("year").value;
    if (document.getElementById('tabber').tabber) {
        url = url + "&page=" + document.getElementById('tabber').tabber.activetab;
    }
    else url = url + "&page=0";
    xmlhttp.onreadystatechange = stateChanged;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
user1876796
  • 31
  • 1
  • 5
  • What have you tried? It would help if you posted sample code of what you have tried so far. – Aaron Kurtzhals Dec 04 '12 at 19:48
  • That's not a "javascript table function" (whatever that is), it's an AJAX call. Without seeing what is returned from this AJAX call, I doubt anyone can help with this question. – Diodeus - James MacFarlane Dec 04 '12 at 19:48
  • Aaron, I only found a way with HTML table, so unfortunately I don't have anything to share. Diodeus, thanks for your answer and explanation. This call returns exactly the same result as in my link above, table of football matches for certain player. Sorry, if I didn't get your answer correctly. – user1876796 Dec 04 '12 at 20:46
  • The page contains a Javascript function that is used to generate (presumably) an HTML table. What code do you use to export an HTML table to Excel? – Zev Spitz Dec 04 '12 at 20:54
  • Zev, for HTML table i got the table straight from Excel. Data->From Web and chose the HTML table from certain webpage. – user1876796 Dec 04 '12 at 21:38

3 Answers3

0

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

user1876796
  • 31
  • 1
  • 5
0

Here is the code using Kendo UI Library :

function save_table_to_excel(id_of_table){
//get the table
    var table = $(id_of_table)[0];

    var workbook = {
        creator: "The programmer",
        sheets:[]
    };

//build the header
    var 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 content
    for (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(new Date(), 'yyyy.MM.dd')+id_of_table+".xlsx"
    });



}
0

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 });
Itamar Smirra
  • 86
  • 1
  • 5