如何向左设置标题对齐,我使用jspdf和jspdf-auto javascript库

码
const doc = new jsPDF("p", "pt", "a4");
doc.autoTable({
startY: 130,
margin: { top: 80, bottom: 20 },
didDrawPage: function (data) {
data.settings.margin.top = 40;
},
bodyStyles: { 2: { halign: 'right' }, 4: { halign: 'right' }, 5: { halign: 'right' }, 6: { halign: 'right' }, 7: { halign: 'right' } },
columnStyles: { 2: { halign: 'right' }, 4: { halign: 'right' }, 5: { halign: 'right' }, 6: { halign: 'right' }, 7: { halign: 'right' } },
headStyles: { halign: 'right' }, // Purple
body: this.PDFArray,
columns: Object.keys(this.PDFArray[0]).map((column) => ({
header: column,
dataKey: column,
})),
theme: "plain",
tableWidth: "auto",
});发布于 2021-02-06 05:53:34
headStyles: { halign: 'right' }将对标题行中的所有单元格进行样式设置,使其对齐。
如果要对单个标头单元格进行样式设置,请将headStyles替换为didParseCell。
didParseCell: data => {
if (data.cell && data.cell.section === 'head') {
switch (data.cell.raw) {
case "SI.":
case "Particulars":
case "Unit":
data.cell.styles.halign = 'left'
break;
default:
data.cell.styles.halign = 'right'
break;
}
}
}您还遵循相同的方法来设置其他样式属性,如font、fontSize、fontStyle、fillColor等。
注意标题列名的大小写,否则单元格可能不会按所需的方式格式化。
https://stackoverflow.com/questions/66022870
复制相似问题