OfficeServer/test-docxtemplater.js
dgsoft a01423321b Complete migration from docx-templates to docxtemplater
 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
2025-10-01 22:14:19 +02:00

48 lines
1.6 KiB
JavaScript

const fs = require('fs');
const Docxtemplater = require('docxtemplater');
const PizZip = require('pizzip');
// Test mit docxtemplater
function testDocxtemplater() {
// Beispiel-Template-Inhalt (normalerweise aus .docx gelesen)
const content = fs.readFileSync('./templates/simple-template.docx', 'binary');
const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {
paragraphLoop: true,
linebreaks: true,
});
// Echte dynamische Daten
const data = {
projekt: "Dynamisches Projekt",
datum: new Date().toLocaleDateString('de-DE'),
mitarbeiter: [
{ nr: 1, name: "Max Mustermann", position: "Developer", email: "max@example.com" },
{ nr: 2, name: "Anna Schmidt", position: "Designer", email: "anna@example.com" },
{ nr: 3, name: "Tom Weber", position: "Manager", email: "tom@example.com" },
{ nr: 4, name: "Lisa König", position: "Analyst", email: "lisa@example.com" },
{ nr: 5, name: "Jan Peters", position: "Tester", email: "jan@example.com" }
],
status: "Aktiv"
};
console.log('📊 Teste mit docxtemplater und', data.mitarbeiter.length, 'Mitarbeitern');
try {
doc.render(data);
const buf = doc.getZip().generate({
type: 'nodebuffer',
compression: 'DEFLATE',
});
fs.writeFileSync('./output/docxtemplater_test.docx', buf);
console.log('✅ docxtemplater Test erfolgreich!');
} catch (error) {
console.log('❌ docxtemplater Fehler:', error.message);
}
}
testDocxtemplater();