my application collects data, transforms it and then saves everything to a Word-document. This is the code which gets the text and saves it to the word document:
Dim DOCXPath as string="C:\\Test"
SelectedIndex="Atlantic City"
Using wordDocument As WordprocessingDocument = WordprocessingDocument.Create(DOCXPath, WordprocessingDocumentType.Document)
' Add a main document part.
Dim mainPart As MainDocumentPart = wordDocument.AddMainDocumentPart()
mainPart.Document = New Document()
Dim body As Body = mainPart.Document.AppendChild(New Body())
Dim para As Paragraph = body.AppendChild(New Paragraph())
Dim run As Run = para.AppendChild(New Run())
Dim justification As Justification = New Justification()
justification.Val = JustificationValues.Center
Dim paragraphProperties1 As ParagraphProperties = New ParagraphProperties
paragraphProperties1.Append(justification)
Dim paragraph As Paragraph = New Paragraph
paragraph.ParagraphProperties = paragraphProperties1
''Loop through the rows
For Each ActualRow As DataRow In DataTablePublication.Rows
'Find the rows matching the Index
If ActualRow.Item(RefDocPubIndex).ToString = SelectedIndex Then
'Write bold
Dim runProperties As RunProperties = run.AppendChild(New RunProperties(New Bold()))
run.AppendChild(New Text(HeaderCreator(ActualRow)))
run.AppendChild(New Paragraph)
'Write bold
run.AppendChild(New RunProperties(New Bold()))
run.AppendChild(New Text(TextCreator1(ActualRow)))
run.AppendChild(New Paragraph)
run.AppendChild(New Text(TextCreator2(ActualRow)))
run.AppendChild(New Paragraph)
End If
Next
wordDocument.Close()
End Using
The function TextCreator2 returns for example the following string:
"Atlantic City had 1 million inhabitants" + Environment.NewLine + "That is wrong!"
The part about the new line is the part which gets somehow "deleted" during the writing to the .docx-file. Can anyone explain me why and how I can solve this?