【发布时间】:2015-10-15 23:40:07
【问题描述】:
我正在使用 Visual Studio 2015 并在 vb.net 中编码并导入 Microsoft.Office.Interop.Word 。我正在使用以下代码创建一个只有两行的单页 Word 文档。如何将这两条线垂直和水平居中?另外,有没有办法将两行(中间有一个换行符)放在一个段落中而不是使用两个?我对这种类型的编程非常陌生,所以请具体说明。谢谢。
Private Sub CreateTitlePage2()
Dim wdApp As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application
Dim wdDoc As Microsoft.Office.Interop.Word.Document = New Microsoft.Office.Interop.Word.Document
Dim wdPara1 As Microsoft.Office.Interop.Word.Paragraph
Dim wdPara2 As Microsoft.Office.Interop.Word.Paragraph
wdDoc.Application.Visible = False
wdPara1 = wdDoc.Content.Paragraphs.Add
wdPara1.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
wdPara1.Range.Font.Bold = True
wdPara1.Range.Text = "BINDER DOCUMENT"
wdPara1.Range.InsertParagraphAfter()
wdPara2 = wdDoc.Content.Paragraphs.Add
wdPara2.Format.SpaceBefore = WdVerticalAlignment.wdAlignVerticalCenter
wdPara2.Range.Font.Bold = True
wdPara2.Range.Text = "Created: " + formattedDate2
wdPara2.Range.InsertParagraphAfter()
wdDoc.SaveAs(binderNameDoc)
wdDoc.Close()
wdApp.Quit()
End Sub
【问题讨论】:
-
当然,这是您在问这里之前可以研究的东西。你能展示你研究过的东西吗?否则,您的问题可能会被否决。
-
代码示例显示了我的一些研究结果,但都不起作用。对于第一段,我尝试使用 Paragraph.Format 对齐并将 WdVerticalAlignment 设置为 wdAlignParagraphCenter。对于第二段,我尝试将 Format.SpaceBefore 设置为相同的值。