| 12345678910111213141516171819202122232425262728293031 |
- // 验证docx库是否正确安装
- const { Document, Paragraph, TextRun } = require('docx');
- console.log('✅ docx库导入成功!');
- console.log('📦 可用的类:');
- console.log(' - Document:', typeof Document);
- console.log(' - Paragraph:', typeof Paragraph);
- console.log(' - TextRun:', typeof TextRun);
- // 测试创建简单文档
- try {
- const doc = new Document({
- sections: [{
- children: [
- new Paragraph({
- children: [
- new TextRun({
- text: "Hello World!",
- bold: true
- })
- ]
- })
- ]
- }]
- });
-
- console.log('✅ 文档创建成功!');
- console.log('✅ docx库功能正常!');
- } catch (error) {
- console.error('❌ 创建文档失败:', error.message);
- }
|