''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Linq
Imports GrapeCity.Documents.Word
Public Class InsertParagraphs
Function CreateDocx() As GcWordDocument
Dim doc = New GcWordDocument()
Dim baseStyle = doc.Styles.Add("Base-style", StyleType.Paragraph)
Dim codeStyle = doc.Styles(BuiltInStyleId.HtmlCode)
Const basePara As String = "This is anchor paragraph number {0}, with style 'Base-style-{0}'."
Dim sepPara As String = vbTab & "--- This is separator between anchors {0} and {1} ---"
doc.Body.Paragraphs.Add(String.Format(sepPara, "start", 1))
Dim p1style = doc.Styles.Add("Base-style-1", baseStyle)
p1style.ParagraphFormat.Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &H7B, &HD3, &HEA)
Dim p1 = doc.Body.Paragraphs.Add(String.Format(basePara, 1), p1style)
doc.Body.Paragraphs.Add(String.Format(sepPara, 1, 2))
Dim p2style = doc.Styles.Add("Base-style-2", baseStyle)
p2style.ParagraphFormat.Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &HC7, &HDB, &H9C)
Dim p2 = doc.Body.Paragraphs.Add(String.Format(basePara, 2), p2style)
doc.Body.Paragraphs.Add(String.Format(sepPara, 2, 3))
Dim p3style = doc.Styles.Add("Base-style-3", baseStyle)
p3style.ParagraphFormat.Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &HFF, &HF0, &H8D)
Dim p3 = doc.Body.Paragraphs.Add(String.Format(basePara, 3), p3style)
doc.Body.Paragraphs.Add(String.Format(sepPara, 3, 4))
Dim p4style = doc.Styles.Add("Base-style-4", baseStyle)
p4style.ParagraphFormat.Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &HFD, &HAB, &H9E)
Dim p4 = doc.Body.Paragraphs.Add(String.Format(basePara, 4), p4style)
doc.Body.Paragraphs.Add(String.Format(sepPara, 4, 5))
Dim p5style = doc.Styles.Add("Base-style-5", baseStyle)
p5style.ParagraphFormat.Shading.BackgroundPatternColor.RGB = Color.FromArgb(&HFF, &HCD, &HC1, &HFF)
Dim p5 = doc.Body.Paragraphs.Add(String.Format(basePara, 5), p5style)
doc.Body.Paragraphs.Add(String.Format(sepPara, 5, "end"))
p1.GetRange().Paragraphs.Insert("Paragraph inserted before paragraph 1 via ", InsertLocation.Before).AddRun(vbLf & "p1.GetRange().Paragraphs.Insert(..., InsertLocation.Before);", codeStyle)
p2.GetRange().Paragraphs.Insert("Paragraph inserted at start of paragraph 2 via ", InsertLocation.Start).AddRun(vbLf & "p2.GetRange().Paragraphs.Insert(..., InsertLocation.Start);", codeStyle)
p3.GetRange().Paragraphs.Insert("Paragraph inserted at end of paragraph 3 via ", InsertLocation.End).AddRun(vbLf & "p3.GetRange().Paragraphs.Insert(..., InsertLocation.End);", codeStyle)
p4.GetRange().Paragraphs.Insert("Paragraph inserted after paragraph 4 via ", InsertLocation.After).AddRun(vbLf & "p4.GetRange().Paragraphs.Insert(..., InsertLocation.After);", codeStyle)
p5.GetRange().Paragraphs.Add("Paragraph added after base paragraph 5 via ").AddRun(vbLf & "p5.GetRange().Paragraphs.Add();", codeStyle)
Return doc
End Function
End Class