Обоснование абзаца в ячейке таблицы с использованием openxml 2.5 - PullRequest
0 голосов
/ 25 октября 2019

Я пытаюсь добавить абзац в ячейку таблицы с центром, но это не работает. Я провожу много исследований в Интернете, а также в стеке, но не повезло. 1. Попробуй добавить центр с помощью Justification и добавить в абзац, не получилось 2. Попробуй добавить центр с помощью Justification и добавить в RunProperties тоже не сово Вот мой код, написанный на vb.net

Function SetFormatHeaderText(txt) As Paragraph
    Dim prg As Paragraph = New Paragraph()
    Dim run As New Run()

    Dim t As Text = New Text(txt)
    Dim rPr As RunProperties = New RunProperties()

    Dim fSize As FontSize = New FontSize() With {.Val = "22"}
    Dim fName As RunFonts = New RunFonts With {.Ascii = "Calibri"}
    'Dim jf As Justification = New Justification With {.Val = JustificationValues.Center}
    Dim b As Bold = New Bold()
    'rPr.Append(jf)
    'prg.AppendChild(Of Justification)(New Justification() With {.Val = JustificationValues.Center})

    rPr.Append(fSize)
    rPr.Append(fName)
    rPr.Append(b)

    run.Append(rPr)
    run.Append(t)

    prg.Append(run)

    Return prg
End Function

Вот вывод для rpt.Append (jf) Дата выпуска

1 Ответ

0 голосов
/ 26 октября 2019

Я нашел решение и надеюсь, что смогу помочь другим людям, которым нужно центрировать ячейку таблицы

Function SetFormatHeaderText(txt) As Paragraph

    'Create a paragraph
    Dim prg As Paragraph = New Paragraph()
    'Paragraph properties to format the text to center
    Dim prgP As ParagraphProperties = New ParagraphProperties()
    'Run the properties change
    Dim rPr As RunProperties = New RunProperties()
    'Run the all change
    Dim run As New Run()

    Dim t As Text = New Text(txt)

    Dim fSize As FontSize = New FontSize() With {.Val = "22"}
    Dim fName As RunFonts = New RunFonts With {.Ascii = "Calibri"}
    Dim jf As Justification = New Justification With {.Val = JustificationValues.Center}
    Dim b As Bold = New Bold()
    'Add center property for paragraph properties
    prgP.Append(jf)
    'Add paragraph properties to paragraph
    prg.Append(prgP)
    'Add text format using run properties
    rPr.Append(fSize)
    rPr.Append(fName)
    rPr.Append(b)

    'Run the text and run properties
    run.Append(rPr)
    run.Append(t)

    'Add the change back to paragraph
    prg.Append(run)

    Return prg
End Function
...