2016-02-25 57 views

回答

0

在MSDN上找到這個例子。不要忘了添加一個參考Microsoft.Office.Interop.Word

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load 
    CreateTableInWordDocument() 
End Sub 

Private Sub CreateTableInWordDocument() 
    Dim objWord As Application 
    Dim objDoc As Document 
    Dim objTable As Table 
    objWord = CreateObject("Word.Application") 
    objWord.Visible = True 
    objDoc = objWord.Documents.Add 
    Dim r As Integer, c As Integer 

    objTable = objDoc.Tables.Add(objDoc.Bookmarks.Item("\endofdoc").Range, 3, 5) 
    objTable.Range.ParagraphFormat.SpaceAfter = 6 
    For r = 1 To 3 
     For c = 1 To 5 
      objTable.Cell(r, c).Range.Text = "Row" & r & " Coulmn" & c 
     Next 
    Next 
    objTable.Rows.Item(1).Range.Font.Bold = True 
    objTable.Rows.Item(1).Range.Font.Italic = True 

End Sub 
相關問題