JSPDF-Autotable colspan/rowpan 问题

标签 jspdf jspdf-autotable

我有一个带有 rowspan/colspan 的 html 表格。我正在使用 jspdf 和 jspdf-autotable 将该 html 表格导出为 pdf。但是,保存的 pdf 有一个表,该表在实际表中不包含 rowspan/colspan。如何使用 jspdf-autotable 执行 colspan/rowspan? 我当前的代码是

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title id='title'>HTML Page setup Tutorial</title> 
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="https://rawgit.com/someatoms/jsPDF-AutoTable/master/dist/jspdf.plugin.autotable.js"></script>

        <script type="text/javascript">
function myFunction()
{

 var doc = new jsPDF('p', 'pt');

    var res = doc.autoTableHtmlToJson(document.getElementById("my-table"));
    doc.autoTable(res.columns, res.data, {startY: 40});
    doc.save("Report.pdf");
}

</script>
    </head>
    <body>
 <table border='1' id="my-table">
<thead>
<tr>
        <th>A</th>
        <th>B</th>
        <th>C</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan='2'>D</td>
<td colspan='2'>$100</td>

</tr>
<tr>
<td >E</td>
<td >F</td>

</tr>
</tbody>
</table>
    <button type="button" onclick="myFunction()">Click Me!</button>
    </body>
</html>  

最佳答案

编辑:库的第 3 版支持行跨度和列跨度,无需修改

该插件不支持从 html 自动移植 colspans 和 rowspans。但是你可以手动完成。看看这个 example (演示是 here )。

关于JSPDF-Autotable colspan/rowpan 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36510636/

相关文章:

javascript - jsAutotable 是否可以选择在超过某个 Y 后继续在新页面上?

javascript - 调整文本autotable jspdf

javascript - 使用 jsPDF 用 JSON 数据填充 PDF

jspdf - 如何使用jspdf为表格内容设置pdf字体大小?

jspdf - 如何在jspdf autoTable的beforePageContent中使用lineBreak

Angular 8,使用 jspdf 和 autotable-jspdf 导入/使用问题

jquery - element.getElementsByTagName 不是 jsPDF 中的函数错误

javascript - 如何在 jspdf.js 中设置导出表格的字体大小?

javascript - jspdf默认 'a4'格式的像素宽度和长度是多少?

javascript - 如何向 JSPDF 添加语言?