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.

Table AutoFit To Content

See original GitHub issue

Initially, I thought about implementing Table AutoFitType, but it seems that AutoFit.ToContent is not something that is automatic but is something that Word does automatically, as in set it to fixes size and then using TabelGrid sizes sets the rest.

I don’t know the magic numbers to count this - but maybe someone does to fix this in future.

public enum AutoFitType {

public AutoFitType? AutoFit {
    get {
        if (this.Width == 0 && WidthType == TableWidthUnitValues.Auto) {
            return AutoFitType.ToContent;
        } else if (this.Width == 5000 && WidthType == TableWidthUnitValues.Pct) {
            return AutoFitType.ToWindow;
        } else if (this.LayoutType == TableLayoutValues.Fixed) {
            return AutoFitType.Fixed;
        return null;
    set {
        if (value == AutoFitType.ToContent) {
            this.Width = 0;
            this.WidthType = TableWidthUnitValues.Auto;
            //this.LayoutType = TableLayoutValues.Autofit;
        } else if (value == AutoFitType.ToWindow) {
            this.Width = 5000;
            this.WidthType = TableWidthUnitValues.Pct;
        } else if (value == AutoFitType.Fixed) {
            this.LayoutType = TableLayoutValues.Fixed;
        } else {
            throw new ArgumentException("Invalid value for AutoFitType. Probably should add null handling");

        public TableGrid GenerateTableGrid()
            TableGrid tableGrid1 = new TableGrid();
            GridColumn gridColumn1 = new GridColumn(){ Width = "3116" };
            GridColumn gridColumn2 = new GridColumn(){ Width = "3117" };
            GridColumn gridColumn3 = new GridColumn(){ Width = "3117" };

            return tableGrid1;

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

PrzemyslawKlyscommented, Oct 7, 2022

i’ve seen it when reading XML files created by Word. The width/height of different things in OfficeIMO is a mess

PrzemyslawKlyscommented, Oct 7, 2022

Then we need to change an API and accept both numbers and strings with percentages or another property

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Adjust Table Columns in Word (AutoFit)
To adjust the column width, click the up and down arrows within the "Width" field. To make all columns the same width, click...
Read more >
Fixing AutoFit Table Columns in Word
Word will automatically adjust or Autofit the width of table columns and the space within cells to fit the content that you are...
Read more >
2 Quick Ways to Auto Fit Tables to Contents or Page in ...
Method 1: Alter Manually · First and foremost, click to select the whole table. · Then, click “Layout” tab under “Table Tools”. ·...
Read more >
AutoFitting Tables (Microsoft Word)
If your table contains information, you can use the mouse to quickly do an AutoFit. You do that by simply double-clicking the mouse...
Read more >
How to Automatically Resize a Table in Microsoft Word
Right-click and move your cursor to AutoFit in the shortcut menu. Then, pick either "AutoFit to Contents" or "AutoFit to Window" in the...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found