perf: 导出word 的目录页面后插入分节符

main
Lei OT 4 months ago
parent d9e9ffa362
commit 18e199deac

@ -248,6 +248,87 @@ const createDoc = async ({title, subject, sectionsData}) => {
// }, // },
}); });
const sectionSettings = {
properties: {
page: {
pageNumbers: {
start: 1,
formatType: NumberFormat.DECIMAL,
},
margin: pageMargins,
},
},
headers: {
default: new docx.Header({
children: [
new docx.Paragraph({
children: [image],
alignment: docx.AlignmentType.LEFT, // Align the image in the header
style: 'Header',
// todo:
// thematicBreak: true,
border: {
top: { style: 'none', size: 10, space: 0, color: 'bf192a' },
bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' },
left: { style: 'none', size: 10, space: 0, color: 'bf192a' },
right: { style: 'none', size: 10, space: 0, color: 'bf192a' },
},
}),
createHeaderRight(),
// createHeaderText(),
],
}),
},
footers: {
default: new docx.Footer({
children: [
new Paragraph({
alignment: AlignmentType.END,
style: 'Footer',
// thematicBreak: true,
border: {
top: { style: 'none', size: 10, space: 0, color: 'bf192a' },
bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' },
left: { style: 'none', size: 10, space: 0, color: 'bf192a' },
right: { style: 'none', size: 10, space: 0, color: 'bf192a' },
},
children: [
new TextRun({
children: ['- ', PageNumber.CURRENT, ' -'],
size: 18,
}),
],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
style: 'Footer',
children: [
new TextRun({
text: '中国 桂林市七里店路70号创意产业园6号楼4层 桂林海纳国际旅行社有限公司 邮编541004',
// break: 1,
}),
new TextRun({
text: 'China Highlights, Discovery Your Way (Since 1959)!',
break: 1,
font: 'Arial',
bold: true,
}),
],
}),
// new Paragraph({
// alignment: AlignmentType.RIGHT,
// children: [
// new TextRun({
// text: `${new Date().toLocaleString()}`,
// italics: true,
// size: 20,
// }),
// ],
// }),
],
}),
},
};
const doc = new docx.Document({ const doc = new docx.Document({
creator: 'China Highlights', creator: 'China Highlights',
subject: 'CH信笺2025', subject: 'CH信笺2025',
@ -395,85 +476,7 @@ const createDoc = async ({title, subject, sectionsData}) => {
}, },
sections: [ sections: [
{ {
properties: { ...sectionSettings,
page: {
pageNumbers: {
start: 1,
formatType: NumberFormat.DECIMAL,
},
margin: pageMargins,
},
},
headers: {
default: new docx.Header({
children: [
new docx.Paragraph({
children: [image],
alignment: docx.AlignmentType.LEFT, // Align the image in the header
style: 'Header',
// todo:
// thematicBreak: true,
border: {
top: { style: 'none', size: 10, space: 0, color: 'bf192a' },
bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' },
left: { style: 'none', size: 10, space: 0, color: 'bf192a' },
right: { style: 'none', size: 10, space: 0, color: 'bf192a' },
},
}),
createHeaderRight(),
// createHeaderText(),
],
}),
},
footers: {
default: new docx.Footer({
children: [
new Paragraph({
alignment: AlignmentType.END,
style: 'Footer',
// thematicBreak: true,
border: {
top: { style: 'none', size: 10, space: 0, color: 'bf192a' },
bottom: { style: 'inset', size: 20, space: 0, color: 'bf192a' },
left: { style: 'none', size: 10, space: 0, color: 'bf192a' },
right: { style: 'none', size: 10, space: 0, color: 'bf192a' },
},
children: [
new TextRun({
children: ['- ', PageNumber.CURRENT, ' -'],
size: 18,
}),
],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
style: 'Footer',
children: [
new TextRun({
text: '中国 桂林市七里店路70号创意产业园6号楼4层 桂林海纳国际旅行社有限公司 邮编541004',
// break: 1,
}),
new TextRun({
text: 'China Highlights, Discovery Your Way (Since 1959)!',
break: 1,
font: 'Arial',
bold: true,
}),
],
}),
// new Paragraph({
// alignment: AlignmentType.RIGHT,
// children: [
// new TextRun({
// text: `${new Date().toLocaleString()}`,
// italics: true,
// size: 20,
// }),
// ],
// }),
],
}),
},
children: [ children: [
createTitle(title), createTitle(title),
new docx.TableOfContents('toc', { new docx.TableOfContents('toc', {
@ -481,6 +484,11 @@ const createDoc = async ({title, subject, sectionsData}) => {
headingStyleRange: '1-5', headingStyleRange: '1-5',
useAppliedParagraphOutlineLevel: true, useAppliedParagraphOutlineLevel: true,
}), }),
],
},
{
...sectionSettings,
children: [
createTitle(subject), createTitle(subject),
...sectionsData.reduce((arr, { tableTitle, tableColumns, tableData }) => { ...sectionsData.reduce((arr, { tableTitle, tableColumns, tableData }) => {

Loading…
Cancel
Save