如何使用officegen nodejs向表格单元格添加自定义图像/样式文本

时间:2016-08-18 05:13:00

标签: node.js

我正在使用officegen使用nodejs创建MS-word文件。到现在为止它完美无缺。 我需要将自定义图像添加到表格单元格。但我想出任何方式。现在我只是使用表的默认示例。

代码:

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);

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

我赞赏任何形式的帮助。提前谢谢

1 个答案:

答案 0 :(得分: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']