Search code examples
c#ms-worddocxnovacode-docx

How can I control table column width in Word documents using DocX?


I am trying to recreate a table like this:

Table

I am using the DocX library to manipulate Word files, but I'm having trouble getting the widths right. Trying to set the widths of cells only seems to work when it's not set to the window autofit mode, and it only seems to resize when the specified width is greater than half of the table width, or rather, I can make a cell bigger than half the width but not smaller.

What would be the simplest way to reproduce the intended table?


Solution

  • I found the answer to this myself. In order to properly set the width, you have to loop through each cell in a column and set every width. This will not work with any autofit options selected.