gpt4 book ai didi

javascript - 仅在表格内部显示边框 autoTable-jsPDF

转载 作者:行者123 更新时间:2023-12-03 08:46:36 25 4
gpt4 key购买 nike

我正在尝试创建一个如下所示的表格:

enter image description here

我已经实现了类似的目标,但我需要删除表格之外的边框。现在我使用 lineWidth: 0.2, lineColor: [73, 138, 159] 来创建边框,但这不是我需要的。我检查了 autoTable-jsPDF 的所有文档,但找不到类似的内容。

有人可以帮我吗?谢谢。

function doPDF() {
var doc = new jsPDF("p", "mm", "a4", true);
var totalPaginas = "{total_pages_count_string}";
var pagActual = 0;

doc.autoTable({
startY: 40,
head: [
[
{
content: "",
colSpan: 5,
styles: { halign: "center", fillColor: [43, 130, 158] }
}
]
],
body: [
[
{
content: "TÍTULO",
colSpan: 1,
styles: {
valign: "middle",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{ content: "TÍTULO", colSpan: 4, styles: { valign: "middle" } }
],
[
{
content: "ESTRATÉGIA DIDÁCTICA",
colSpan: 1,
styles: {
valign: "middle",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "ESTRATÉGIA DIDÁCTICA",
colSpan: 4,
styles: { valign: "middle" }
}
],
[
{
content: "OBJETIVOS",
colSpan: 1,
styles: {
valign: "middle",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{ content: "OBJETIVOS", colSpan: 4, styles: { valign: "middle" } }
],
[
{
content: "ESPACIO",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "TIEMPO",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "DINÁMICA",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "SITUACIÓN DE JUEGO",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "COORDINACIÓN",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
}
],
[
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } }
],
[{ content: "", colSpan: 5 }]
],
columnStyles: {
0: { cellWidth: 40 }
},
bodyStyles: {
lineWidth: 0.2,
lineColor: [73, 138, 159]
},
theme: "plain"
});

var primera_tabla = doc.lastAutoTable.finalY;

doc.autoTable({
head: [
[
{
content: "ACCIÓN TÉCNICA / COORDINATIVA",
styles: { halign: "center", fillColor: [244, 247, 249] }
},
{
content: "INTENCIÓN TÁCTICA / PRINCIPIO COLECTIVO",
styles: { halign: "center", fillColor: [244, 247, 249] }
}
]
],
styles: {
lineColor: [73, 138, 159],
lineWidth: 0.2
},
theme: "plain",
startY: primera_tabla
});

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPaginas);
}

doc.save("pdf.pdf");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.4.3/jspdf.plugin.autotable.min.js"></script>

<button onclick="doPDF()">Do</button>

最佳答案

您可以使用以下技巧在 table 周围绘制白色边框:

doc.autoTable({
// ...
tableLineColor: [255, 255, 255],
tableLineWidth: 1,
})

function doPDF() {
var doc = new jsPDF("p", "mm", "a4", true);
var totalPaginas = "{total_pages_count_string}";
var pagActual = 0;

doc.autoTable({
startY: 40,
head: [
[
{
content: "",
colSpan: 5,
styles: { halign: "center", fillColor: [43, 130, 158] }
}
]
],
body: [
[
{
content: "TÍTULO",
colSpan: 1,
styles: {
valign: "middle",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{ content: "TÍTULO", colSpan: 4, styles: { valign: "middle" } }
],
[
{
content: "ESTRATÉGIA DIDÁCTICA",
colSpan: 1,
styles: {
valign: "middle",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "ESTRATÉGIA DIDÁCTICA",
colSpan: 4,
styles: { valign: "middle" }
}
],
[
{
content: "OBJETIVOS",
colSpan: 1,
styles: {
valign: "middle",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{ content: "OBJETIVOS", colSpan: 4, styles: { valign: "middle" } }
],
[
{
content: "ESPACIO",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "TIEMPO",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "DINÁMICA",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "SITUACIÓN DE JUEGO",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
},
{
content: "COORDINACIÓN",
styles: {
valign: "middle",
halign: "center",
fillColor: [244, 247, 249],
fontStyle: "bold"
}
}
],
[
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } },
{ content: "text", styles: { valign: "middle", halign: "center" } }
],
[{ content: "", colSpan: 5 }]
],
columnStyles: {
0: { cellWidth: 40 }
},
bodyStyles: {
lineWidth: 0.2,
lineColor: [73, 138, 159]
},
theme: "plain",
tableLineColor: [255, 255, 255],
tableLineWidth: 1,
});

var primera_tabla = doc.lastAutoTable.finalY;

doc.autoTable({
head: [
[
{
content: "ACCIÓN TÉCNICA / COORDINATIVA",
styles: { halign: "center", fillColor: [244, 247, 249] }
},
{
content: "INTENCIÓN TÁCTICA / PRINCIPIO COLECTIVO",
styles: { halign: "center", fillColor: [244, 247, 249] }
}
]
],
styles: {
lineColor: [73, 138, 159],
lineWidth: 0.2
},
theme: "plain",
startY: primera_tabla
});

if (typeof doc.putTotalPages === "function") {
doc.putTotalPages(totalPaginas);
}

doc.save("pdf.pdf");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.4.3/jspdf.plugin.autotable.min.js"></script>

<button onclick="doPDF()">Do</button>

关于javascript - 仅在表格内部显示边框 autoTable-jsPDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61231635/

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