我正在尝试使用open xml将格式应用于文本。我想添加Bold,18磅字体并让它居中。
粗体和字体大小格式正确应用但我无法使中心对齐正常工作。这是我第一次使用开放式XML,非常感谢任何帮助。
Dim mainPart As MainDocumentPart = mydoc.AddMainDocumentPart()
mainPart.Document = New Document()
Dim body As New Body()
Dim paragraph As New Paragraph()
Dim run_paragraph As New Run()
'we want to put that text into the output document
Dim text_paragraph As New Text("Executive Summary - " + name)
'Append elements appropriately.
'bold
Dim RunProperties As RunProperties = run_paragraph.AppendChild(New RunProperties())
Dim Bold As New Bold
Bold.Val = OnOffValue.FromBoolean(True)
Dim fontSize As New FontSize
fontSize.Val = "22"
RunProperties.AppendChild(fontSize)
RunProperties.AppendChild(Bold)
'center
Dim paragraphProperties As ParagraphProperties = run_paragraph.AppendChild(New ParagraphProperties())
Dim justification As New Justification
justification.Val = JustificationValues.Center
paragraphProperties.AppendChild(justification)
run_paragraph.AppendChild(text_paragraph)
paragraph.Append(run_paragraph)
body.Append(paragraph)
mainPart.Document.Append(body)
mainPart.Document.Save()
Response.Redirect("~/summaries/" + documentfilename)
答案 0 :(得分:2)
尝试将paragraphProperties
添加到paragraph
对象(而不是run_paragraph
)
替换:
Dim paragraphProperties As ParagraphProperties = run_paragraph.AppendChild(New ParagraphProperties())
使用:
Dim paragraphProperties As ParagraphProperties = paragraph.AppendChild(New ParagraphProperties())