CopyKeepSource.vb
''
'' 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 CopyKeepSource
    Function CreateDocx() As GcWordDocument
        Const styleName As String = "X-style"

        Dim doc = New GcWordDocument()

        Dim xStyleTgt = doc.Styles.Add(styleName, StyleType.Paragraph)
        xStyleTgt.Font.Color.RGB = Color.Blue
        xStyleTgt.Font.Bold = True
        xStyleTgt.ParagraphFormat.Indentation.RightIndent += 72
        Dim textTgt = $"This paragraph in the target document " &
            $"is associated with a custom paragraph style named ""{styleName}"". " &
            $"That style specifies the font to be blue and bold, and the whole paragraph " &
            $"is indented by 1"" on the right."
        doc.Body.Paragraphs.Add(textTgt, doc.Styles(styleName))

        Dim docSrc = New GcWordDocument()
        Dim xStyleSrc = docSrc.Styles.Add(styleName, StyleType.Paragraph)
        xStyleSrc.Font.Color.RGB = Color.Red
        xStyleSrc.Font.Italic = True
        xStyleSrc.ParagraphFormat.Alignment = ParagraphAlignment.Right
        xStyleSrc.ParagraphFormat.Indentation.LeftIndent += 72
        Dim textSrc = "This paragraph is copied from the source to the target DOCX. " &
            $"In the source DOCX, this paragraph was associated with a custom style also named ""{styleName}"". " &
            $"That style specifies the font to be red and italic, the whole paragraph is right-aligned " &
            $"and indented 1"" from the left. " &
            $"Due to a conflict with the same-named but different style in the target document " &
            $"its name is changed to ""{styleName}1""."
        Dim paraSrc = docSrc.Body.Paragraphs.Add(textSrc, docSrc.Styles(styleName))

        paraSrc.GetRange().CopyTo(doc.Body, InsertLocation.End, FormattingCopyStrategy.KeepSource)

        Return doc
    End Function
End Class