Working with Word for WinForms / Advanced Level Working / Adding Complex Text
Adding Complex Text

Adding text, images, tables and graphics to your document makes it more interactive. Using Word component, you can easily add title, images, tables, and graphics to your word document. Till now, you have seen how to add simple text to your document. But your document is actually a composite set of text, images, pictures, graphics etc which actually constitutes a complex text. The code given below adds title, images, tables, and graphics to your word document - all in one code:

' add title
C1Word.AddParagraph(C1Word.Info.Title, New Font("Tahoma", 24, FontStyle.Italic), Color.BlueViolet)

' add image
C1Word.AddParagraph("picture:", New Font("Courier New", 9, FontStyle.Regular), Color.Black)
Dim img As New Bitmap(GetManifestResource("picture.jpg"))
C1Word.AddPicture(img, RtfHorizontalAlignment.Center)

' add table
C1Word.LineBreak()
Dim rows As Integer = 7
Dim cols As Integer = 2
Dim table As New RtfTable(rows, cols)
C1Word.Add(table)
For row As Integer = 0 To rows - 1
        For col As Integer = 0 To cols - 1
                Dim paragraph As New RtfParagraph()
                paragraph.Content.Add(New RtfString(String.Format("table cell {0}:{1}.", row, col)))
                table.Rows(row).Cells(col).Content.Add(paragraph)
        Next
Next

' add graphics
C1Word.LineBreak()
C1Word.DrawLine(Pens.Green, 200, 90, 400, 90)

Dim rc = New RectangleF(150, 170, 90, 40)
Using pen As New Pen(Brushes.Blue, 5F)
        C1Word.DrawRectangle(pen, rc)
End Using
C1Word.FillRectangle(Color.Gold, rc)
C1Word.ShapeFillOpacity(50)
C1Word.ShapeRotation(25)

rc = New RectangleF(300, 120, 80, 80)
C1Word.DrawEllipse(Pens.Red, rc)
C1Word.FillEllipse(Color.Pink, rc)
C1Word.ShapeFillOpacity(70)