godocx icon indicating copy to clipboard operation
godocx copied to clipboard

Paragraph alignment

Open itispx opened this issue 1 year ago • 1 comments

Hello, loved the library but is there a way to align my paragraph to the center, right or justify the content?

If there's a way I could not find it in the documentation or the examples.

Thanks

itispx avatar May 20 '24 15:05 itispx

Figure out that you can access justification via p.Property.Justification, however p.Property is nil at first, so the best way I was able to make it work was as follows:

p := docx.AddEmptyParagraph()
p.Property = elements.DefaultParaProperty()
p.Property.Justification = elements.NewJustification("both")

itispx avatar May 20 '24 15:05 itispx

I am glad that you find it useful. It needs more work, will try to add more features. Thanks for the raising this issue. It is simplified in > 0.0.8-alpha release https://github.com/gomutex/godocx/releases/tag/v0.0.8-alpha

You can now do

p1 := docx.AddParagraph("Center Justified example")
p1.Justification("center")

gomutex avatar May 31 '24 05:05 gomutex