6

我的示例(只需单击“导出 PDF”):https ://jsfiddle.net/j9vaqpnz/7/

我的示例导出我的表,如下所示:

在此处输入图像描述 .

然后使用库jspdfautotable将表导出为 pdf 。

在导出函数期间,我使用“drawCell”函数,对于所有包含数字的列,我将它们右对齐,如下所示:

drawCell: function (cell, data) {
                var col = data.column.index;
                if(col==3 || col==5 || col==6 || col==7 || col==8 || col==9 || col==10){
                    cell.styles.halign = 'right';
                }
            }

.

问题:在 PDF 中,我右对齐的所有列都定位不正确,它看起来像这样:

在此处输入图像描述

这是一个错误吗?或者我可能不正确地使用“drawCell”?

4

2 回答 2

4

使用“didParseCell”(v3.x)时,右对齐可以正确定位元素。

更新示例:https ://jsfiddle.net/j9vaqpnz/10/

新代码:

...
didParseCell: function (cell, data) {
    alignCol(cell, data);
}
...

function alignCol(data){
    var col = data.column.index;
    if(col==3 || col==5 || col==6 || col==7 || col==8 || col==9 || col==10){
        data.cell.styles.halign = 'right';
    }
}
于 2017-01-30T13:11:16.333 回答
1

columnStyles您可以使用属性对齐单元格

const pdf = new jsPDF();

pdf.autoTable({

    ...

    columnStyles: {
        3: {
            halign: 'right'
        },
        5: {
            halign: 'right'
        },
        6: {
            halign: 'right'
        },
        7: {
            halign: 'right'
        },
        8: {
            halign: 'right'
        },
        9: {
            halign: 'right'
        },
        10: {
            halign: 'right'
        }
    }
});

jsPDF-AutoTable 文档

于 2020-12-22T17:00:40.920 回答