Search code examples
javascriptnode.jsdocx

How can I remove table borders with DocxJS?


Let's say I want to remove all of the borders from this table:

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

Following the documentation online: 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" }),
            ],
          }),
        ],
      }),
     ],
  })

This gives:

   image    |    text    

According to the documentation, moving the border options inside the TableCell should impact the cell's borders, but I see no results when I do so. Any ideas how to achieve a table without any borders?


Solution

  • As mentioned by @cbloss793, It seems that border options for TableCell must also contain the size: 0 attribute to remove the corresponding border. I also added color: "FFFFFF" just to be safe.

    ...
    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"},
            },
    ...