Javascript 如何在jsPdf表格中设置表格

Javascript 如何在jsPdf表格中设置表格,javascript,angular,jquery-ui,ionic2,jspdf,Javascript,Angular,Jquery Ui,Ionic2,Jspdf,您好,我正在使用jsPdf将报告导出为pdf 我的密码在这里 import { Component, OnInit, AfterViewInit, Inject, ViewChild, ElementRef } from '@angular/core'; import * as jsPDF from 'jspdf'; @Component({ templateUrl: 'goldenSignature.component.html', providers: [UserService,

您好,我正在使用jsPdf将报告导出为pdf 我的密码在这里

 import { Component, OnInit, AfterViewInit, Inject, ViewChild, ElementRef } from '@angular/core';
import * as jsPDF from 'jspdf';

@Component({
  templateUrl: 'goldenSignature.component.html',
  providers: [UserService,
    { provide: 'Window', useValue: window }
  ],
})

export class GoldenSignatureComponent {  

  download() {
    let type;
    if (this.type) {
      type = this.type;
    }
    else {
      type = this.message.allProducts;
    }
    let columns = ["S.No", "Product Name", "Product Type", "Brand Name", "Model Name", "Sample Size", "Status", "Version Number"];
    let data = [];
    let headers = { "S.No": "S.No", "Product Name": "Product Name", "Product Type": "Product Type", "Brand Name": "Brand Name", "Model Name": "Model Name", "Sample Size": "Sample Size", "Status": "Status", "Version Number": "Version Number" };
    data.push(headers);
    if (type == this.message.allProducts) {
      for (let i = 0, j = 1; i < this.data.length; i++) {
        let data1 = {};
        data1 = { "S.No": j, "Product Name": this.data[i].productName, "Product Type": this.data[i].productType, "Brand Name": this.data[i].brandName, "Model Name": this.data[i].modelName, "Sample Size": this.data[i].sampleSize, "Status": this.data[i].status, "Version Number": this.data[i].versionNo };
        data.push(data1);
        j++;
      }
    }
    else {
      for (let i = 0, j = 1; i < this.data.length; i++) {
        if (type == this.data[i].productName) {
          let data1 = {};
          data1 = { "S.No": j, "Product Name": this.data[i].productName, "Product Type": this.data[i].productType, "Brand Name": this.data[i].brandName, "Model Name": this.data[i].modelName, "Sample Size": this.data[i].sampleSize, "Status": this.data[i].status, "Version Number": this.data[i].versionNo };
          data.push(data1);
          j++;
        }
      }
    }
    var doc = new jsPDF('landscape', 'pt');
    doc.setFontSize(18);
    doc.setTextColor(0, 0, 0);
    doc.text(300, 100, type);
    let styles = {
      autoSize: true,
      printHeaders: false,
      columnWidths: 80
    }
    doc.table(100, 150, data, columns, styles);
    doc.save(this.message.pdfGoldenSignature);
  }   

}
从'@angular/core'导入{Component,OnInit,AfterViewInit,Inject,ViewChild,ElementRef};
从“jsPDF”导入*为jsPDF;
@组成部分({
templateUrl:'goldenSignature.component.html',
提供者:[用户服务,
{provide:'Window',useValue:Window}
],
})
导出类GoldenSignatureComponent{
下载(){
let型;
if(this.type){
type=this.type;
}
否则{
类型=this.message.allProducts;
}
设列=[“序号”、“产品名称”、“产品类型”、“品牌名称”、“型号名称”、“样本量”、“状态”、“版本号”];
让数据=[];
让标题={“S.No”:“S.No”,“Product Name”:“Product Name”,“Product Type”:“Product Type”,“Brand Name”:“Brand Name”,“Model Name”:“Model Name”,“Sample Size”:“Sample Size”,“Status”:“Status”,“Version Number”:“Version Number”};
数据推送(标题);
if(type==this.message.allProducts){
for(设i=0,j=1;i
一切正常问题是我想设置表和表列的宽度。请告诉任何人如何设置表的宽度和表的其他属性
提前感谢

您必须使用jsPdf的不同功能来提供适当的边距和填充,以适当的方式表示可能是一项繁琐的任务

相反,你可以试试那个工作很好的插件,它提供了不同的样式/主题。你可以很容易地自定义列和行的高度和宽度


很抱歉,我无法使用jsPdf自动表格。该表格一直显示jsPdf未定义。我已经尝试了所有版本,你导入jspdf正确吗?你愿意分享你更新的代码吗?你写了什么。@S k这是我更新的完整代码,关于自动表格,我刚刚复制粘贴了安装插件后的演示代码