gpt4 book ai didi

javascript - jsPDF 类型不存在属性 'autoTable'

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:18 25 4
gpt4 key购买 nike

我正在使用 angular2Node JS。我已经安装了jspdfjspdf-autotable两个模块都使用 npm。在 angular-cli.json 文件中,我嵌入了脚本:

"scripts": [ 
"../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
],

在我的 component.ts 文件中,我按如下方式导入了这些文件:

 import * as jsPDF from 'jspdf'; 
import * as autoTable from 'jspdf-autotable';

我也试过这些行来导入 jspdf-autotable

import { autoTable } from 'jspdf-autotable'; 
import 'jspdf-autotable';

但没有任何效果。

component.ts 文件的函数中,我使用的示例代码如下:

var columns = ["ID", "Country", "Rank", "Capital"];
var data = [
[1, "Denmark", 7.526, "Copenhagen"],
[2, "Switzerland", 7.509, "Bern"],
[3, "Iceland", 7.501, "Reykjavík"],
[4, "Norway", 7.498, "Oslo"],
[5, "Finland", 7.413, "Helsinki"]
];
var doc = new jsPDF();
doc.autoTable(columns, data);
doc.output("dataurlnewwindow");

但是现在当我运行 node 命令来启动应用程序然后在编译过程中出现错误:

Property 'autoTable' does not exist on type 'jsPDF'.

谁能推荐一下?

最佳答案

以下在 Angular 11、jsPDF 2.3.1、jspdf-autotable 3.5.14 中对我有用:

import jsPDF from 'jspdf'
import autoTable from 'jspdf-autotable'

public printTable() {

const doc = new jsPDF('l', 'mm', 'a4');

const head = [['ID', 'Country', 'Index', 'Capital']]
const data = [
[1, 'Finland', 7.632, 'Helsinki'],
[2, 'Norway', 7.594, 'Oslo'],
[3, 'Denmark', 7.555, 'Copenhagen'],
[4, 'Iceland', 7.495, 'Reykjavík'],
[5, 'Switzerland', 7.487, 'Bern'],
[9, 'Sweden', 7.314, 'Stockholm'],
[73, 'Belarus', 5.483, 'Minsk'],
]

autoTable(doc, {
head: head,
body: data,
didDrawCell: (data) => { },
});

doc.save('table.pdf');
}

关于javascript - jsPDF 类型不存在属性 'autoTable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47344349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com