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 layout fixed has no effect #1948

Open
Niccober opened this issue Feb 16, 2023 · 2 comments
Open

Table layout fixed has no effect #1948

Niccober opened this issue Feb 16, 2023 · 2 comments

Comments

@Niccober
Copy link

I am trying to generate a table with a fixed width for each column. According to the Open XML docs (http://officeopenxml.com/WPtableLayout.php) setting the TableLayout parameter should cause the table in the word document to keep the inital column widths independent of the cell contents. So whenever a string becomes too long the cell should not auto-extend but keep its size - forcing the text to wrap (even if it does not look nice and the break happens within a single word).

In my understanding this should be achievable using the TableLayout property if it is set to FIXED. This approach was also proposed here in the past: #1139

Here's the code I use to generate the table:

new docx.Table({
  width: {
    size: 100,
    type: docx.WidthType.PERCENTAGE
  },
  layout: docx.TableLayoutType.FIXED,
  rows: [
    new docx.TableRow({ children: [
      new docx.TableCell({
        width:{
          size: 50,
          type: docx.WidthType.PERCENTAGE
        },
        children:[
          new docx.Paragraph({ children: [
            new docx.TextRun({ text: 'Lovely text for lovely paragraph'})
          ] })
        ]
      }),
      new docx.TableCell({
        width:{
          size: 50,
          type: docx.WidthType.PERCENTAGE
        },
        children:[
          new docx.Paragraph({ children: [
            new docx.TextRun({ text: 'longlonglonglonglonglonglonglonglonglonglonglongloonglonglonglonglonglonglonglonglong'})
          ] })
        ]
      })
    ]})
  ]
})

The result looks like this:
image

So although in the code is specified that the table should have a width of 50 % for each cell and the layout should be fixed, the table still auto-adjusts the column widths. The behaviour is the same if I specify the cell widhts in DXA instead of percent. No matter whether I set the table layout to fixed or not, the rendered table in the word file always auto-adjusts the columns when the contents become too long. In the table properties this circumstance is also reflected:
image

The highlighted property says "Allow automatic size adjustment" and should refer to the TableLayout property. When I manually deselect that property, the table is rendered as expected and forces the text in the second column to wrap:
image

I am not sure if I am doing something wrong or if this is maybe a bug. Any help on that would be highly appreciated. Regarding that issue I am also wondering what is the difference between defining the columnWidths property directly at the table object vs. providing the widths in the table cells objects using the width object with size and type? Do they cause different behaviour or is it the same?

@damian-garrido
Copy link

hi @Niccober
i'm not sure if my response would work to you, but when i use the width for a cell i define this like:

width: { size: '5%', type: WidthType.PERCENTAGE },

the size as string with the simbol of percentage (%)
saludos!

@Niccober
Copy link
Author

Niccober commented Mar 9, 2023

Hi @damian-garrido thanks your answer but it has no effect I am afraid. Interestingly, your approach does not throw an error but according to the docs, size should actually be a numeric and then be interpreted in combination with the type property.

@dolanmiu Do you have an idea regarding the inital issue (see above)?

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

No branches or pull requests

2 participants