Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table styles don't work in online word #877

Open
tripodsan opened this issue Apr 3, 2021 · 4 comments
Open

Table styles don't work in online word #877

tripodsan opened this issue Apr 3, 2021 · 4 comments
Labels

Comments

@tripodsan
Copy link

tripodsan commented Apr 3, 2021

Online word has problems with custom table styles.
for example the https://github.com/dolanmiu/docx/blob/master/demo/25-table-xml-styles.ts demo produces this in word:

image

but this in online word:

image


tested with docx-6.0.3

@dolanmiu dolanmiu added the bug label Apr 3, 2021
@tripodsan
Copy link
Author

I think the problem is the column widths:

{
  "deleted": false,
  "rootKey": "w:tblGrid",
  "root": [
    {
      "deleted": false,
      "rootKey": "w:gridCol",
      "root": [
        {
          "deleted": false,
          "rootKey": "_attr",
          "root": {
            "w": 100
          },
          "xmlKeys": {
            "w": "w:w"
          }
        }
      ]
    },
    {
      "deleted": false,
      "rootKey": "w:gridCol",
      "root": [
        {
          "deleted": false,
          "rootKey": "_attr",
          "root": {
            "w": 100
          },
          "xmlKeys": {
            "w": "w:w"
          }
        }
      ]
    }
  ]
}

if you don't specify them, they are initialized with 100, which is very small :-) as they are 1/1440 of an inch:
http://officeopenxml.com/WPtableGrid.php

I found this works for me best:

  const tbl = new Table({
    rows,
    width: {
      size: 5000,
      type: WidthType.PERCENTAGE,
    },
  });
  const grid = findXMLComponent(tbl, 'w:tblGrid');
  if (grid) {
    tbl.root.splice(tbl.root.indexOf(grid), 1);
  }

@dolanmiu
Copy link
Owner

dolanmiu commented Apr 4, 2021

Yup, it's set to 100 by default on purpose (I randomly picked 100 at the time of writing the code)

So this is a non-issue I suppose?

@tripodsan
Copy link
Author

So this is a non-issue I suppose?

yes, it is an issue. if you omit the columnWidths when creating the table, you add widths with 100. this makes the tables unusable on online-word. the correct behaviour would be to not create a w:tblGrid component if no columnWidths is specified. this makes word to auto size the columns.

@dolanmiu
Copy link
Owner

dolanmiu commented Apr 5, 2021

Makes sense, will make a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants