Skip to content

Commit

Permalink
fix #1225
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Jan 8, 2024
1 parent 3459f55 commit ab6221c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ooxml/XWPF/Model/XWPFHeaderFooterPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace NPOI.XWPF.Model
using NPOI.OpenXmlFormats.Vml;
using NPOI.OpenXmlFormats.Vml.Office;
using System.Diagnostics;
using static System.Net.WebRequestMethods;

/**
* A .docx file can have no headers/footers, the same header/footer
Expand Down Expand Up @@ -438,12 +439,23 @@ public void CreateWatermark(String text)
private XWPFParagraph GetWatermarkParagraph(String text, int idx)
{
CT_P p = new CT_P();
byte[] rsidr = doc.Document.body.GetPArray(0).rsidR;
byte[] rsidrdefault = doc.Document.body.GetPArray(0).rsidRDefault;
p.rsidP = (rsidr);
p.rsidRDefault = (rsidrdefault);
byte[] rsidr = null;
byte[] rsidrdefault = null;
CT_Body ctBody = doc.Document.body;
if(ctBody.SizeOfPArray() != 0)
{
CT_P ctp = ctBody.GetPArray(0);
rsidr = ctp.rsidR;
rsidrdefault = ctp.rsidRDefault;
}
else
{
// TODO generate rsidr and rsidrdefault
}
p.rsidP = rsidr;
p.rsidRDefault = rsidrdefault;
CT_PPr pPr = p.AddNewPPr();
pPr.AddNewPStyle().val = ("Header");
pPr.AddNewPStyle().val = "Header";
// start watermark paragraph
NPOI.OpenXmlFormats.Wordprocessing.CT_R r = p.AddNewR();
CT_RPr rPr = r.AddNewRPr();
Expand Down

0 comments on commit ab6221c

Please sign in to comment.