Google Table Chart导出为具有自动表格的PDF

问题描述 投票:1回答:1

[嗨,我正尝试将Google表格图表导出为PDF。我已经尝试过这种方式:

var doc = new jsPDF('p','pt','a4');
        doc.text(15, 15, 'Batemo Cell Finder Report');
        // doc.addImage(ScatterChart.getChart().getImageURI(), 15, 40, 180, 160);
        doc.autoTable(document.getElementById("table_div"), 15, 15, {
          'width': 200,
          'elementHandlers': specialElementHandlers,
        });
        doc.save('chart.pdf');

但是它在浏览器中显示以下控制台错误:

Uncaught TypeError: Cannot create property 'body' on number '15'
    at parseUserArguments (jspdf.plugin.autotable.js:1276)
    at Object.parseInput (jspdf.plugin.autotable.js:1195)
    at Object.autoTable (jspdf.plugin.autotable.js:1154)
    at HTMLInputElement.<anonymous> (cell_finder.html:287)

如何获取显示的数据。提前非常感谢!

google-visualization
1个回答
0
投票

Google表格图表的确会生成普通的html <table>。但是,它包含在一个或多个<div>元素中。

也许autotable需要一个表元素,而不是一个div ...

尝试直接提供表格元素...

    doc.autoTable(document.querySelector('#table_div table')[0], 15, 15, {
      'width': 200,
      'elementHandlers': specialElementHandlers,
    });
© www.soinside.com 2019 - 2024. All rights reserved.