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 exp
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
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"
});
}