Question

I'm using Word automation to construct a table, I need one column to be very narrow but every time I use Microsoft.Office.Interop.Word.Column.SetWidth method to set the width, it throws "value out of range Exception" it works if I make it a larger value but it is critical to be as small as it could get

someone suggested that the spacing and padding be set to zero, which I did, but it still throws the exception

      table.LeftPadding = 0;
      table.RightPadding = 0;
      table.Spacing = 0;
      table.Columns[4].SetWidth(9f, WdRulerStyle.wdAdjustNone);
Was it helpful?

Solution

SetWidth take parameter in points. Try this

table.Columns[4].SetWidth(
    Globals.ThisAddIn.Application.MillimetersToPoints(9f), 
    WdRulerStyle.wdAdjustNone);

or use this

table.Columns[4].PreferredWidth = 9f;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top