2016-08-18 477 views
2

我正在使用officegen使用nodejs创建MS-word文件。到现在为止,它工作得很好。 我需要将自定义图像添加到表格单元格。但我想出任何办法。现在我只是使用它们的默认示例来表格。如何使用officegen nodejs将自定义图像/样式文本添加到表单元格

代码:

var officegen = require('officegen'); 
var docx = officegen ('docx'); 
var table = [ 
    [{ 
    val: "No.", 
    opts: { 
     cellColWidth: 4261, 
     b:true, 
     sz: '48', 
     shd: { 
     fill: "7F7F7F", 
     themeFill: "text1", 
     "themeFillTint": "80" 
     }, 
     fontFamily: "Avenir Book" 
    } 
    },{ 
    val: "Title1", 
    opts: { 
     b:true, 
     color: "A00000", 
     align: "right", 
     shd: { 
     fill: "92CDDC", 
     themeFill: "text1", 
     "themeFillTint": "80" 
     } 
    } 
    },{ 
    val: "Title2", 
    opts: { 
     align: "center", 
     vAlign: "center", 
     cellColWidth: 42, 
     b:true, 
     sz: '48', 
     shd: { 
     fill: "92CDDC", 
     themeFill: "text1", 
     "themeFillTint": "80" 
     } 
    } 
    }], 
    [1,'All grown-ups were once children','I need to add custom image here'], 
    [2,'there is no harm in putting off a piece of work until another day.',''], 
    [3,'But when it is a matter of baobabs, that always means a catastrophe.',''], 
    [4,'watch out for the baobabs!','END'], 
] 

var tableStyle = { 
    tableColWidth: 4261, 
    tableSize: 24, 
    tableColor: "ada", 
    tableAlign: "left", 
    tableFontFamily: "Comic Sans MS", 
    borders: true 
} 

docx.createTable (table, tableStyle); 

上面的代码能够创建一个自定义表。但我无法在表格单元中添加自定义图像或段落。

我喜欢任何形式的帮助。在此先感谢

+0

我没有得到任何的解决方案,所以我分叉的officegen项目和延长功能。 https://github.com/FaheemAlam/officegen。 对不起,我不喜欢fork分支,但我需要这个功能尽快。 –

回答

0

对于化妆的第一行 在第一个单元格,而不是

[1,'All grown-ups were once children','I need to add custom image here'] 

使用

[{"val":1,"opts":{place here your desired options - same notation as heading opts}},'All grown-ups were once children','I need to add custom image here'] 
相关问题