B4J Question Justify paragraph with XLUtils

LGS

Member
Licensed User
Longtime User
Hello everyone
I am creating a word document trying to justify a paragraph.
$"[p Alignment=Center]text here[/p]"$

I have tried to use all the constants described in:
https://poi.apache.org/apidocs/dev/org/apache/poi/xwpf/usermodel/ParagraphAlignment.html
But I can only adjust the text, and I can't justify it

I found the following:
https://stackoverflow.com/questions/43427006/how-can-i-do-to-justify-a-paragraph-with-apache-poi

I included the following:
Me.as(JavaObject).RunMethod("justifica", Array(doc.XWPFDocument.RunMethod("getParagraphArray",Array(1))))

#if java
import org.apache.poi.xwpf.usermodel.*;
public static void justifica(XWPFParagraph ParagraphToModify) {
//ParagraphToModify.setAlignment(ParagraphAlignment.BOTH);
//ParagraphToModify.setAlignment(ParagraphAlignment.THAI_DISTRIBUTE);
ParagraphToModify.setAlignment(ParagraphAlignment.DISTRIBUTE);
}
#EndIf

But equally the text is not justified, it is only aligned.

1709513308964.png


1709513233686.png


Small program attached

I would like to know if there is a way to justify the text of a specific paragraph.

Thanks in advance
 

Attachments

  • WordExample.zip
    16.2 KB · Views: 24

teddybear

Well-Known Member
Licensed User
I don't understand totally your question, is this the result which you want?
1709524272355.png
 
Upvote 0

LGS

Member
Licensed User
Longtime User
Hello
The images I showed are the result of using "THAI_DISTRIBUTE" and "DISTRIBUTE", which fill the first line with white spaces.

When using "DISTRIBUTE" the word "erat." distributes it throughout the line, filling it with white spaces

Apparently it is something related to the end of line when creating text with paragraphs [p][/p]

What I need?
Justify unfilled lines with white spaces

Something like that:
1709559178407.png
 
Upvote 0

LGS

Member
Licensed User
Longtime User
I found a way using THAI_DISTRIBUTE

When creating multiple lines in a single paragraph using $""$
B4X:
[p alignment=THAI_DISTRIBUTE] here multiple lines [/p]
For some reason unknown to me, it is not justified correctly(fill in the lines with blank spaces).

So, I separated the lines:
Dim parrafos() As String = Regex.Split(Chr(10), paragraphs)

And I create an individual paragraph for each line:
For x=0 To parrafos.Length-1
    Log(parrafos(x))
    paragraphs = paragraphs & Chr(10) & $"[p alignment=THAI_DISTRIBUTE]${parrafos(x)}[/p]"$ ' & chr(10) NOT NECESSARY. JUST TO SEE THE LOG
Next

I don't know if it's the most efficient, but it works for me.

I attached a small program in case someone needs it.

I appreciate the help šŸ¤
 

Attachments

  • WordExample.zip
    15.9 KB · Views: 21
Upvote 0
Top