【问题标题】:having troubles with making a multiple html table download using tabulator?使用制表器下载多个 html 表格时遇到问题?
【发布时间】:2019-04-28 09:56:55
【问题描述】:

我可以使用制表器在一个页面上呈现两个表格。现在我需要将两个表都导出到一个 Excel 工作簿(不同的工作表)中。

我尝试了文档中提供的示例,但未能成功。

head 标签中包含的脚本

{{-- tabulator links --}}
<link rel="stylesheet" href="css/tabulator/tabulator_simple.css" rel="stylesheet">
<link rel="stylesheet" href="css/tabulator/tabulator_custom.css" rel="stylesheet">
<script src="js/tabulator/tabulator.min.js"></script>

{{-- XLSX Script Includes --}}
<script type="text/javascript" src="http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js"></script>

我放置的正文标签:

<br />
<input class="btn btn-default" type="button" id="download-xlsx" value="Download Excel">
<br />

{{-- tabulator table --}}
<br> table-1 caption <br />
<div id="tableOne" style="margin-top:15px"></div>

<br> table-2 caption <br />
<div id="tableTwo" style="margin-top:15px"></div>

这就是我在脚本标签中的内容

//define data
    var one = {!!$one!!}

    //define table
    var table = new Tabulator("#tableOne", {
        data:one,
        autoColumns:true,
        height:"500px",
        layout:"fitDataFill",
        selectable:true,
        clipboard:true,
    });

    //define data
    var two = {!!$two!!}

    //define table
    var table = new Tabulator("#tableTwo", {
        data:two,
        autoColumns:true,
        height:"500px",
        layout:"fitDataFill",
        // layout:"fitColumns",
        selectable:true,
        clipboard:true,
    });    

    //trigger download of data.xlsx file
    var sheets = {
    "sheetA": "#tableOne",
    "sheetB": "#tableTwo",
    };

    $("#download-xlsx").click(function(){
    table.download("xlsx", "AllData.xlsx", {sheets:sheets});
});

单击下载按钮时,将打开 2 张 Excel 工作簿。第一张表包含第一张桌子,没关系。但第二张纸是空的。为什么会这样?

【问题讨论】:

    标签: javascript laravel tabulator


    【解决方案1】:

    请看这个demo你需要把表格变量放在你要下载的表格变量中创建一个空的table0来合并和下载它们

    var sheets = {
    "Example Data1": table1,
        "Example Data2": table2
    };
    
        downloadXlxs = function(){
    table0.download("xlsx", "data.xlsx", {sheets:sheets});
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多