如何使用 DocxJS 删除表格边框?

问题描述 投票:0回答:2

假设我想删除该表中的所有边框:

---------------------------
|   image    |    text    |
---------------------------

遵循在线文档:https://docx.js.org/#/usage/tables

new Table({
   borders: {
              top: {style: BorderStyle.NONE},
              bottom: {style: BorderStyle.NONE},
              left: {style: BorderStyle.NONE},
              right: {style: BorderStyle.NONE},
            },
    rows: [
      new TableRow({
        children: [
          new TableCell({
            children: [
              new Paragraph({ children: [some_image_file] }),
            ],
          }),
          new TableCell({
            children: [
              new Paragraph({ text: "text" }),
            ],
          }),
        ],
      }),
     ],
  })

这给出:

   image    |    text    

根据文档,移动

TableCell
内的边框选项应该会影响单元格的边框,但这样做时我看不到任何结果。有什么想法如何实现没有边框的表格吗?

javascript node.js docx
2个回答
5
投票

正如@cbloss793所提到的,似乎

TableCell
的边框选项还必须包含
size: 0
属性以删除相应的边框。为了安全起见,我还添加了
color: "FFFFFF"

...
new TableCell({
   borders: {
          top: {style: BorderStyle.NONE, size: 0, color: "FFFFFF"},
          bottom: {style: BorderStyle.NONE, size: 0, color: "FFFFFF"},
          left: {style: BorderStyle.NONE, size: 0, color: "FFFFFF"},
          right: {style: BorderStyle.NONE, size: 0, color: "FFFFFF"},
        },
...

0
投票

对我来说,使用 DocxJS v. 8.2.3,使用

BorderStyle.NIL
可以删除单元格边框。

new TableCell({
   borders: {
          top: {style: BorderStyle.NIL },
          bottom: {style: BorderStyle.NIL },
          left: {style: BorderStyle.NIL },
          right: {style: BorderStyle.NIL },
        },

我不需要设置

size
color

现在用户可以在浅黄色纸张上打印,而不会看到微弱的白色单元格边框。

© www.soinside.com 2019 - 2024. All rights reserved.