Vb.net 使用openxml 2.5在表格单元格中对齐段落
我尝试将段落添加到具有中心的表格单元格中,但它不起作用。 我在互联网上做了很多研究,还有stackoverflow,但没有幸运。 1.尝试使用对齐方式添加中心,并添加到段落中,但无效 2.尝试使用对齐方式添加中心,并将其添加到RunProperties中,但也没有使用owk 这是我用vb.net编写的代码Vb.net 使用openxml 2.5在表格单元格中对齐段落,vb.net,ms-word,openxml,Vb.net,Ms Word,Openxml,我尝试将段落添加到具有中心的表格单元格中,但它不起作用。 我在互联网上做了很多研究,还有stackoverflow,但没有幸运。 1.尝试使用对齐方式添加中心,并添加到段落中,但无效 2.尝试使用对齐方式添加中心,并将其添加到RunProperties中,但也没有使用owk 这是我用vb.net编写的代码 Function SetFormatHeaderText(txt) As Paragraph Dim prg As Paragraph = New Paragraph() Di
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)的输出
发行日期我找到了解决方案,希望能帮助其他需要将表格单元格居中的人
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
您是否尝试在OpenXMLSDK生产力工具中打开一个(小)示例文档,并查看生成该文档的代码?马上,我要说的是,您需要在段落属性(
pPr
)中指定段落格式(对齐方式)。谢谢Cindy,我让它工作了