We're sorry Aspose doesn't work properply without JavaScript enabled.

# How to get Table AutoFitBehavior

Hello. How do we get the Table AutoFitBehavior?

e.g.

Assert.Equal(AutoFitBehavior.AutoFitToContents, table.???);


Thanks!

There is no way to find out which of the auto fit methods was applied. In MS Word there is no way to do this too - Autofit drop-down does not show which method was applied previously – you can just choose what to apply right now. Please check this screenshot.

But you may be able to get the desired output by using the existing API. For example, if AllowAutoFit == false and PreferredWidth == PreferredWidth.Auto, it means AutoFitBehavior.FixedColumnWidths was applied. If AllowAutoFit == true and Table.PreferredWidth == PreferredWidth.FromPercent(100), it means AutoFitBehavior.AutoFitToWindow was applied. the following code may work for you:

Document doc = new Document("D:\\Temp\\in.docx");

Table tab = doc.FirstSection.Body.Tables[0];

if (!tab.AllowAutoFit && tab.PreferredWidth.Equals(PreferredWidth.Auto))
{
Console.WriteLine("AutoFitBehavior.FixedColumnWidths is applied on this table");
}
else if (tab.AllowAutoFit && tab.PreferredWidth.Equals(PreferredWidth.FromPercent(100)))
{
Console.WriteLine("AutoFitBehavior.AutoFitToWindow is applied on this table");
}
else
{
Console.WriteLine("AutoFitBehavior.AutoFitToContents is applied on this table");
}


Hope, this helps.