0

我找到了一种将 HTML 表导出到 Excel 的方法,但是在将 JavaScript 表导出从网站导出到 Excel 时遇到问题。请帮我找到一种方法,将此表导出到 Excel。

页面,我需要信息的地方:

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);
4

3 回答 3

0

我自己找到了答案。

javascript函数从页面获取信息:

http://www.jalgpall.ee/db/getplayergame.php?reg=ellermaasoft&player=28469&&sid=0.1&year=2012&page=0

从这个页面我可以直接将数据导出到 Excel,使用 Excel->Data->Export Data from Web

于 2012-12-07T08:57:02.253 回答
0

这是使用Kendo UI 库的代码:

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



}
于 2015-09-09T13:09:15.993 回答
0

您还可以使用包fs-browsers
它为 xls 文件提供了简单易用的导出方法。
它是这样的:

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

于 2021-10-12T15:47:42.503 回答