简体   繁体   English

来自 HTML 表格的 jsPDF AutoTable rowspan/colspan

[英]jsPDF AutoTable rowspan/colspan from HTML table

I'm using jsPDF AutoTable ( https://github.com/simonbengtsson/jsPDF-AutoTable ).我正在使用 jsPDF AutoTable ( https://github.com/simonbengtsson/jsPDF-AutoTable )。

I have an HTML table with rowspan="2" and when the pdf is generated with this table, there is no rowspan="2" anymore :(我有一个带有 rowspan="2" 的 HTML 表格,当使用此表格生成 pdf 时,不再有 rowspan="2" :(

I modify the plugin to add rowSpan attribute (see [[[[[ ADDED ]]]]] mark ) :我修改插件以添加 rowSpan 属性(参见 [[[[[ADDED ]]]]] 标记):

var autoTableHtmlToJson = function(table){

    var data = [],
        headers = [],
        header = table.rows[0],
        tableRow,
        rowData,
        i,
        j;

    for( i = 0 ; i < header.cells.length;i++){
        headers.push( (typeof header.cells[i] !== "undefined") ? header.cells[i].textContent : "" );
    }

    for( i = 1 ; i < table.rows.length; i++ ){
        tableRow = table.rows[i];
        rowData = [];

        for( j = 0; j < header.cells.length; j++ ){
            if( typeof tableRow.cells[j] !== "undefined" ){
                rowData.push({
                    value   : tableRow.cells[j].textContent,
                    rowSpan : tableRow.cells[j].rowSpan <==== [[[[[ ADDED ]]]]]
                });
            }
            else{
                rowData.push({
                    value   : "",
                    rowSpan : 1 <==== [[[[[ ADDED ]]]]]
                });
            }
        }
        data.push( rowData );
    }
    return { columns:headers, data:data, rows:data }
};

Then for each cell to draw I have :然后对于要绘制的每个单元格,我有:

    drawCell: function (cell, data) {
                    doc.rect(cell.x, cell.y, cell.width, cell.height * cell.raw.rowSpan, 'S');
                    doc.autoTableText(cell.raw.value,cell.x + cell.width / 2, cell.y + cell.height * cell.raw.rowSpan, {
                    halign: 'center',
                    valign: 'middle',
                    overflow: 'linebreak'
                });
                return false;

                }

The rowSpan has the right value in drawCell but the pdf result is very wrong ! rowSpan 在 drawCell 中具有正确的值,但 pdf 结果非常错误! The pdf have all data on the same line and I don't know why. pdf 的所有数据都在同一行,我不知道为什么。 Sorry I can't post the screenshot because I have not the reputation for.抱歉,我无法发布屏幕截图,因为我没有声誉。

EDIT: Rowspans, colspans and css styling are now supported and should work out of the box docs编辑:Rowspans,colspans和CSS样式现在支持,并应工作开箱文档

The jspdf-autotable plugin currently only supports converting data from an html table. jspdf-autotable插件目前只支持从 html 表格转换数据。 All styling including rowspans etc have to be applied manually.所有样式,包括 rowspans 等都必须手动应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM