我找到了一种将HTML表格导出到Excel的方法,但是我将导出JavaScript表格从网站导出到Excel时遇到了问题。请帮我找到一种方法,将此表导出到Excel。
Page,从哪里我需要信息:
www.jalgpall.ee/players.php?year=2012&team=84&player=28469&b=ML
此页面的javascript表函数示例:
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);
答案 0 :(得分:0)
我自己找到了答案。
javascript函数从页面获取其信息:
http://www.jalgpall.ee/db/getplayergame.php?reg=ellermaasoft&player=28469&&sid=0.1&year=2012&page=0
从此页面我可以使用Excel-> Data->从Web导出数据
将数据直接导出到Excel答案 1 :(得分:0)
以下是使用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"
});
}