I want to create a new document with headers and footers. This is the code I am trying but it is not showing any header in the document, whereas the body content is available.
using (WordprocessingDocument doc = WordprocessingDocument.Create(HttpContext.Current.Server.MapPath("~/QEC/Reports/reportXML.docx"), DocumentFormat.OpenXml.WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = doc.AddMainDocumentPart();
HeaderPart hdrPart = mainPart.AddNewPart<HeaderPart>();
hdrPart.Header = new Header();
Paragraph hdrPara = hdrPart.Header.AppendChild(new Paragraph());
Run paraRun = hdrPara.AppendChild(new Run());
paraRun.AppendChild(new Text("Hello"));
mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document();
Body body = mainPart.Document.AppendChild(new Body());
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Text("Done"));
}
Aucun commentaire:
Enregistrer un commentaire