diff --git a/_examples/document/tables/main.go b/_examples/document/tables/main.go index 0ec03d68..329b6e1d 100644 --- a/_examples/document/tables/main.go +++ b/_examples/document/tables/main.go @@ -194,6 +194,8 @@ func main() { tp.Borders().SetAll(wml.ST_BorderSingle, color.Blue, 0.5*measurement.Point) table := doc.AddTable() + + table.Properties().SetLayout(wml.ST_TblLayoutTypeFixed) table.Properties().SetWidthPercent(90) table.Properties().SetStyle("MyTableStyle") look := table.Properties().TableLook() diff --git a/_examples/document/tables/tables.docx b/_examples/document/tables/tables.docx index dfa3c416..3b4c85d0 100644 Binary files a/_examples/document/tables/tables.docx and b/_examples/document/tables/tables.docx differ diff --git a/document/tableproperties.go b/document/tableproperties.go index 38ff0568..1d72828b 100644 --- a/document/tableproperties.go +++ b/document/tableproperties.go @@ -63,6 +63,19 @@ func (t TableProperties) SetWidthPercent(pct float64) { t.x.TblW.WAttr.ST_DecimalNumberOrPercent.ST_UnqualifiedPercentage = gooxml.Int64(int64(pct * 50)) } +// SetLayout controls the table layout. wml.ST_TblLayoutTypeAutofit corresponds +// to "Automatically resize to fit contents" being checked, while +// wml.ST_TblLayoutTypeFixed corresponds to it being unchecked. +func (t TableProperties) SetLayout(l wml.ST_TblLayoutType) { + // ST_TblLayoutTypeAutofit is the default + if l == wml.ST_TblLayoutTypeUnset || l == wml.ST_TblLayoutTypeAutofit { + t.x.TblLayout = nil + } else { + t.x.TblLayout = wml.NewCT_TblLayoutType() + t.x.TblLayout.TypeAttr = l + } +} + // SetAlignment sets the alignment of a table within the page. func (t TableProperties) SetAlignment(align wml.ST_JcTable) { if align == wml.ST_JcTableUnset {