简体   繁体   English

如何将带有代码的表格样式分配给Word文档

[英]how to assign table styles with code to a word document

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 我正在使用工作中创建的Visual Basic 2010软件的数据创建Word文档,该文档包含在报告中……我被要求生成Microsoft Word文档,因此现在我要创建一个表格并填充该文档数据表,像这样

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 has some table designs styles like "DARK LIST - ACCENT 5". Microsoft Word具有一些表设计样式,例如“ 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? “ DARK LIST-ACCENT 6”等,我不知道如何在表格中设置此样式,这可能吗?

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

Assign the style: 分配样式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM