B4J Question [XLUtils] Creating Word without empty line

MarcoRome

Expert
Licensed User
Longtime User
Hi All.
I have the following code:

B4X:
Dim sb As StringBuilder
    sb.Initialize
    
    'Giorno
    Dim TitleCellStyle As String = "color=black width=600 VerticalAlignment=center"
    Dim TitlePStyle As String = "[p alignment=center][color=white][b]"
    sb.Append($"
        [table Alignment=Left rows=${1} cols=1]
            this is the header row
            [row RepeatHeader=True]
                [cell ${TitleCellStyle}]${TitlePStyle}Dieta Diversa - Sabato 23 Aprile 2022[/b][/color][/p][/cell]
            [/row]
            
        "$)
    sb.Append("[/table]")
    
    
    'Per Test
    Dim tipo As List
    tipo.Initialize
    tipo.Add("COLAZIONE")
    tipo.Add("SPUNTINO1")
    tipo.Add("SPUNTINO2")
    'ciclo per Pranzo , spuntino, etc
    For ii = 0 To 2
    
    'Tipo Pasto
    Dim TitleCellStyle As String = "color=green width=600 VerticalAlignment=center"
    Dim TitlePStyle As String = "[p alignment=left][color=black][b]"
    sb.Append($"
        [table Alignment=Left rows=${1} cols=1]
            this is the header row
            [row RepeatHeader=True]
                [cell ${TitleCellStyle}]${TitlePStyle}${tipo.Get(ii)}[/b][/color][/p][/cell]
            [/row]
        "$)
    sb.Append("[/table]")
    
    'Una riga vuota
    sb.Append($"[p] [/p]"$)
    
    'Il contenuto del Pasto + Note + eventuali GR   

        Dim items As List
        items.Initialize
        For i = 1 To 20
            items.Add(Array("Item " & i, Rnd(1, 100), Rnd(100, 1000)))
        Next
        
        ......
        
        Dim TitleCellStyle As String = "color=yellow width=200 VerticalAlignment=center"
        Dim TitlePStyle As String = "[p alignment=center][color=black][b]"
        sb.Append($"
    [table Alignment=Center rows=${1 + items.Size} cols=3]
        this is the header row
        [row RepeatHeader=True]
            [cell ${TitleCellStyle}]${TitlePStyle}Cosa[/b][/color][/p][/cell]
            [cell ${TitleCellStyle}]${TitlePStyle}Note[/b][/color][/p][/cell]
            [cell ${TitleCellStyle}]${TitlePStyle}Gr[/b][/color][/p][/cell]
        [/row]
    "$)
    
        For Each row() As Object In items
            sb.Append($"
        [row height=10]
            [cell][p alignment=center]${row(0)}[/p][/cell]
            [cell][p alignment=center]${row(1)}[/p][/cell]
            [cell][p alignment=center]$${row(2)}[/p][/cell]
        [/row]
        "$)
        Next
        sb.Append("[/table]")  
    Next
    Return sb.ToString

I get the following result, there is a space between the green and yellow lines

1651466708119.png


due to the following line of code:
B4X:
'Una riga vuota
sb.Append($"[p] [/p]"$)

if i delete the line the result is the following:

1651466928629.png



I would like the following result:

1651466963356.png


Any suggestion ?
Thank you
Marco
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
If you look to this simple code:
Watch the different between first and last newline in the log:
Log("-----")
    Log( $"
    Line one
    Line two
    Line three
    "$)
    Log("-----")
    Log( _
    $"
    Line one
    Line two
    Line three
    "$)
    Log("-----")

The first Newline is stripped from the log while the last Newline is included. So what happen when you change this line
current code line:
    sb.Append($"
        [table Alignment=Left rows=${1} cols=1]
            this is the header row
            [row RepeatHeader=True]
[cell ${TitleCellStyle}]${TitlePStyle}${tipo.Get(ii)}[/b][/color][/p][/cell]
            [/row]
        "$)
updated code line:
    sb.Append($"
        [table Alignment=Left rows=${1} cols=1]
            this is the header row
            [row RepeatHeader=True]
[cell ${TitleCellStyle}]${TitlePStyle}${tipo.Get(ii)}[/b][/color][/p][/cell][/row]"$)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Se guardi a questo semplice codice:
Guarda la differenza tra la prima e l'ultima riga di nuovo nel registro:
Log("-----")
    Registro( $"
    Riga uno
    Riga due
    Riga tre
    "$)
    Tronco d'albero("-----")
    Tronco d'albero( _
    $"
    Riga uno
    Riga due
    Riga tre
    "$)
    Log("-----")[/CODICE]

La prima Newline viene rimossa dal registro mentre l'ultima Newline viene inclusa. Quindi cosa succede quando cambi questa linea
[CODE lang="b4x" title="linea di codice corrente"]
    sb.Append($"
        [Allineamento tabella=Righe a sinistra=${1} cols=1]
            questa è la riga di intestazione
            [riga RepeatHeader=Vero]
[cell ${TitleCellStyle}]${TitlePStyle}${tipo.Get(ii)}[/b][/color][/p][/cell]
            [/riga]
        "$)
[/CODICE]
[CODE lang="b4x" title="linea di codice aggiornata"]
    sb.Append($"
        [Allineamento tabella=Righe a sinistra=${1} cols=1]
            questa è la riga di intestazione
            [riga RepeatHeader=Vero]
[cell ${TitleCellStyle}]${TitlePStyle}${tipo.Get(ii)}[/b][/color][/p][/cell][/row]"$)
[/CODICE]
[/QUOTE]
Nothing. Same thing

Nothing. There is no difference
 
Upvote 0
Top