I am trying to use C # to replace a specific line of text in an entire DOCX file with line break (new line).
The line of text I'm looking for can be in a paragraph or in a table in a file.
I am currently using the following code to replace text.
using (WordprocessingDocument doc = WordprocessingDocument.Open("yourdoc.docx", true)) { var body = doc.MainDocumentPart.Document.Body; foreach (var text in body.Descendants<Text>()) { if (text.Text.Contains("##Text1##")) { text.Text = text.Text.Replace("##Text1##", Environment.NewLine); } } }
QUESTION:. When I run this code, the DOCX output file replaces the text instead of a space (i.e. "").
How can I change this code to do this?
c # ms-word openxml docx openxml-sdk
slayernoah Oct 10 '14 at 20:37 2014-10-10 20:37
source share