question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

autofit is broken

See original GitHub issue

Hi, the autofit method is broken in 0.8.5. Tables behave like if the columns have fixed width. When autofit is set, tag(s) <w:tcW/> for the table(s) in document.xml should be set to something like <w:tcW w:type="auto" w:w="0"/> and not <w:tcW w:type="dxa" w:w="13606"/> (for example)

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
Simarracommented, Dec 16, 2019

Here is a snippet to the autofit works. It load every tables and set tblW and cells width to type auto.

Any idea how to implement it to the library core library? Adding a tblW children to tblPr and update the autofit setter?

def set_autofit(doc: Document) -> Document:
    """
    Hotfix for autofit.
    """
    for t_idx, table in enumerate(doc.tables):
        doc.tables[t_idx].autofit = True
        doc.tables[t_idx].allow_autofit = True
        doc.tables[t_idx]._tblPr.xpath("./w:tblW")[0].attrib["{http://schemas.openxmlformats.org/wordprocessingml/2006/main}type"] = "auto"
        for row_idx, r_val in enumerate(doc.tables[t_idx].rows):
            for cell_idx, c_val in enumerate(doc.tables[t_idx].rows[row_idx].cells):
                doc.tables[t_idx].rows[row_idx].cells[cell_idx]._tc.tcPr.tcW.type = 'auto'
                doc.tables[t_idx].rows[row_idx].cells[cell_idx]._tc.tcPr.tcW.w = 0
    return doc
3reactions
scannycommented, Nov 14, 2017

The cells in a column can be set to have w:type="auto" using this code:

for cell in column.cells:
    tc = cell._tc
    tcPr = tc.get_or_add_tcPr()
    tcW = tcPr.get_or_add_tcW()
    tcW.type = 'auto'

If you’re willing to depend on the w:tcPr and w:tcW elements already being there, it can be shortened to:

for cell in column.cells:
    cell._tc.tcPr.tcW.type = 'auto'

If someone has a proposal for when that should be done automatically, I’m willing to consider it, just clearly state the behavior you propose.

Read more comments on GitHub >

github_iconTop Results From Across the Web

You cannot use the AutoFit feature for rows or columns that ...
In Excel, you cannot use the AutoFit feature on a column that contains a cell merged with cells in other columns. Likewise, you...
Read more >
row autofit not working
This problem occurs if you have manually modified the height of the row. ... To adjust the height of the row to fit...
Read more >
[Fixed] AutoFit Row Height Not Working for Merged Cells in ...
But if your Excel worksheet contains any merged cell, then the AutoFit Row Height and the AutoFit Column Width will not work there....
Read more >
AutoFit Row Height and Column Width not working : r/excel
I'm at a loss! The AutoFit Row Height and AutoFit Column Width features in excel are not working for me. When I attempt...
Read more >
Resizing object with 'Auto-Fit' enabled now broken in 15.1
In version 15.0.3 and earlier, if you enabled the 'Auto-Fit' option and then resized an object by entering values in the Width or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found