✅ Migration completed: - server.js: Complete rewrite using docxtemplater + pizzip - server-old.js: Backup of original docx-templates implementation - package.json: Added docxtemplater and pizzip dependencies - Removed docx-templates dependency 🚀 New features: - True dynamic tables with {#array}{field}{/array} syntax - Unlimited table rows (no more fixed array indices) - New API endpoints: /analyze, /generate, /demo - Simplified template creation scripts 🎯 Template improvements: - Updated template syntax examples - Added dynamic-template.docx with loop syntax - Enhanced template analysis functionality 📊 Benefits: - Real dynamic table generation - Better template flexibility - Cleaner API design - Preserved SSL and WebDAV functionality
63 lines
3.1 KiB
JavaScript
63 lines
3.1 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell } = require('docx');
|
|
|
|
async function createRealDynamicTemplate() {
|
|
const doc = new Document({
|
|
sections: [{
|
|
properties: {},
|
|
children: [
|
|
new Paragraph({
|
|
children: [new TextRun({ text: "ECHTE DYNAMISCHE TABELLEN", bold: true, size: 32 })],
|
|
}),
|
|
new Paragraph({ children: [new TextRun({ text: "" })] }),
|
|
new Paragraph({ children: [new TextRun({ text: "Projekt: ++projekt++" })] }),
|
|
new Paragraph({ children: [new TextRun({ text: "Datum: ++datum++" })] }),
|
|
new Paragraph({ children: [new TextRun({ text: "" })] }),
|
|
new Paragraph({ children: [new TextRun({ text: "MITARBEITER:", bold: true, size: 24 })] }),
|
|
new Table({
|
|
rows: [
|
|
// Header Row
|
|
new TableRow({
|
|
children: [
|
|
new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: "Nr.", bold: true })] })] }),
|
|
new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: "Name", bold: true })] })] }),
|
|
new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: "Position", bold: true })] })] }),
|
|
new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: "E-Mail", bold: true })] })] }),
|
|
],
|
|
}),
|
|
// Template Row - mit w:tr repeat
|
|
new TableRow({
|
|
children: [
|
|
new TableCell({
|
|
children: [new Paragraph("++FOR mitarbeiter++Nr: ++nr++")]
|
|
}),
|
|
new TableCell({
|
|
children: [new Paragraph("++name++")]
|
|
}),
|
|
new TableCell({
|
|
children: [new Paragraph("++position++")]
|
|
}),
|
|
new TableCell({
|
|
children: [new Paragraph("++email+++/FOR++")]
|
|
}),
|
|
],
|
|
}),
|
|
],
|
|
}),
|
|
new Paragraph({ children: [new TextRun({ text: "" })] }),
|
|
new Paragraph({ children: [new TextRun({ text: "Status: ++status++" })] }),
|
|
],
|
|
}],
|
|
});
|
|
|
|
const buffer = await Packer.toBuffer(doc);
|
|
const templatePath = path.join(__dirname, 'templates', 'tabellen-template.docx');
|
|
fs.writeFileSync(templatePath, buffer);
|
|
|
|
console.log('✅ Template mit FOR-Loop Syntax erstellt');
|
|
console.log('📋 Syntax: ++FOR mitarbeiter++...++/FOR++');
|
|
}
|
|
|
|
createRealDynamicTemplate().catch(console.error);
|