如何将带有代码的表格样式分配给Word文档 [英] how to assign table styles with code to a word document
问题描述
我正在使用我为自己的工作而创建的Visual Basic 2010软件创建的数据创建Word文档,该文档包含在报告中……我被要求生成Microsoft Word文档,因此现在我要创建一个表并用数据填充该表,就像这样
I'm creating a word document with data from a Visual Basic 2010 software I created for my work, which consist in a report ... i was ask to generate a Microsoft word document, so now I'm creating a table and filling that table with data, something likes this
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 8, 4)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Range.Font.Size = 10
oTable.Rows.Item(1).Range.Font.Bold = True
oTable.Rows.Item(1).Range.Font.Italic = True
oTable.Cell(1, 1).Range.Text = "Datos de Facturación:"
oTable.Cell(1, 3).Range.Text = " Enviar a:"
oTable.Cell(2, 1).Range.Text = rs.Text
oTable.Cell(2, 1).Width = 75
oTable.Cell(3, 1).Range.Text = dirfa.Text
oTable.Cell(3, 1).Width = 75 ..... etc..
Microsoft Word具有一些表设计样式,例如"DARK LIST-ACCENT 5". "DARK LIST-ACCENT 6"等,我不知道如何在表格中设置此样式,这可能吗?
Microsoft Word has some table designs styles like "DARK LIST - ACCENT 5". "DARK LIST - ACCENT 6" etc, I couldn't figure out how to set this styles to the table, is it possible?
推荐答案
要创建样式,可以使用文档对象:
To create a style, you can use a document object:
Set doc = wd.Documents.Add(NewTemplate:=True)
With doc.Styles("Certificate")
With .Font
.Name = "Arial"
.Size = 12
.Italic = True
.Bold = True
End With
With .ParagraphFormat
''wdAlignParagraphCenter = 1
.Alignment = 1
.SpaceAfter = 0
.SpaceBefore = 0
End With
End With
分配样式:
Set r = doc.Shapes("Course1").TextFrame.TextRange
r.Style = "Certificate"
在这种情况下,您可以使用:
For this particular case, you might use:
oTable.Range.Style = "ANewStyle"
或者如果您可以使用内置样式:
Or if built-in styles are available to you:
oTable.Rows.Item(1).Range.Style = WdBuiltinStyle.wdStyleHeading1
这篇关于如何将带有代码的表格样式分配给Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!