89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell } = require('docx');
|
|
|
|
// Erstelle ein einfaches Test-Template mit der richtigen Syntax für docx-templates
|
|
async function createTestTemplate() {
|
|
const doc = new Document({
|
|
sections: [{
|
|
properties: {},
|
|
children: [
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "RECHNUNG",
|
|
bold: true,
|
|
size: 32,
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "Kunde: ++name++",
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "E-Mail: ++email++",
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "Datum: ++date++",
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "",
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "ARTIKEL",
|
|
bold: true,
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "Artikel 1: ++items[0].product++ (++items[0].quantity++x) - ++items[0].price++€",
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "",
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({
|
|
children: [
|
|
new TextRun({
|
|
text: "Gesamtsumme: ++total++€",
|
|
bold: true,
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
}],
|
|
});
|
|
|
|
const buffer = await Packer.toBuffer(doc);
|
|
const outputPath = path.join(__dirname, 'templates', 'simple-template.docx');
|
|
fs.writeFileSync(outputPath, buffer);
|
|
|
|
console.log('✅ Einfaches Template erstellt:', outputPath);
|
|
}
|
|
|
|
createTestTemplate().catch(console.error); |