I want to add a section break at the end of the document and add some text.
My code is as below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace WordDocManipulation
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\sample.docx";
string strtxt = "Hello This is done by programmatically";
OpenAndAddTextToWordDocument(path,strtxt);
}
public static void OpenAndAddTextToWordDocument(string filepath, string txt)
{
/* I want to the below text to be added in the new section */
// Open a WordprocessingDocument for editing using the filepath.
WordprocessingDocument wordprocessingDocument =
WordprocessingDocument.Open(filepath, true);
// Assign a reference to the existing document body.
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
// Add new text.
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Text(txt));
// Close the handle explicitly.
wordprocessingDocument.Close();
}
}
}
What should I do?
sectionProperties
entry at the end. When adding a break the pages before loose those properties. Any idea how to make sure the page properties aren't lost? – Gumma