JSPDF-Autotable colspan/rowpan问题 [英] JSPDF-Autotable colspan/rowpan issue

查看:225
本文介绍了JSPDF-Autotable colspan/rowpan问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an html table with rowspan/colspan.I am using jspdf and jspdf-autotable for exporting that html table to pdf. However the pdf getting saved has a table which doesn't contain rowspan/colspan in actual table.How to do colspan/rowspan using jspdf-autotable? My current code is

<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支持rowpans和colspans,无需黑客操作

Version 3 of the library supports rowspans and colspans, no hacks needed

该插件不支持从html自动移植colspans和rowpans.但是,您可以手动执行此操作.查看此示例(演示是此处).

The plugin doesn't support to automatically port colspans and rowspans from html. However you can do it manually. Check out this example (a demo is here).

这篇关于JSPDF-Autotable colspan/rowpan问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆