【问题标题】:Justification paragraph in table cell using openxml 2.5使用openxml 2.5的表格单元格中的对齐段落
【发布时间】:2019-10-24 22:29:27
【问题描述】:

我尝试将段落添加到居中的表格单元格中,但它不起作用。 我在互联网和stackoverflow上做了很多研究,但没有幸运。 1.尝试使用Justification添加中心并添加到段落中,没有奏效 2.尝试使用 Justification 添加中心并添加到 RunProperties 也没有 owk 这是我在 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) 的输出 发行日期

【问题讨论】:

  • 您是否尝试在 Open XML sDK 生产力工具中打开一个(小)示例文档并查看生成该文档的代码?马上,我想说您需要在 Paragraph Properties (pPr) 中指定段落格式(对齐方式)
  • 谢谢辛迪,我成功了

标签: vb.net ms-word openxml


【解决方案1】:

我找到了解决方案,希望可以帮助其他需要居中表格单元格的人

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

【讨论】:

    猜你喜欢
    • 2019-06-09
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    相关资源
    最近更新 更多