public TOC(CT_SdtBlock block) { this.block = block; CT_SdtPr sdtPr = block.AddNewSdtPr(); CT_DecimalNumber id = sdtPr.AddNewId(); id.val = ("4844945"); sdtPr.AddNewDocPartObj().AddNewDocPartGallery().val = ("Table of contents"); CT_SdtEndPr sdtEndPr = block.AddNewSdtEndPr(); CT_RPr rPr = sdtEndPr.AddNewRPr(); CT_Fonts fonts = rPr.AddNewRFonts(); fonts.asciiTheme = (ST_Theme.minorHAnsi); fonts.eastAsiaTheme = (ST_Theme.minorHAnsi); fonts.hAnsiTheme = (ST_Theme.minorHAnsi); fonts.cstheme = (ST_Theme.minorBidi); rPr.AddNewB().val = false; rPr.AddNewBCs().val = false; rPr.AddNewColor().val = ("auto"); rPr.AddNewSz().val = 24; rPr.AddNewSzCs().val = 24; CT_SdtContentBlock content = block.AddNewSdtContent(); CT_P p = content.AddNewP(); byte[] b = Encoding.Unicode.GetBytes("00EF7E24"); p.rsidR = b; p.rsidRDefault = b; p.AddNewPPr().AddNewPStyle().val = ("TOCHeading"); p.AddNewR().AddNewT().Value = ("Table of Contents"); }
public TOC(CT_SdtBlock block) { this.block = block; CT_SdtPr ctSdtPr = block.AddNewSdtPr(); ctSdtPr.AddNewId().val = "4844945"; ctSdtPr.AddNewDocPartObj().AddNewDocPartGallery().val = "Table of contents"; CT_RPr ctRpr = block.AddNewSdtEndPr().AddNewRPr(); CT_Fonts ctFonts = ctRpr.AddNewRFonts(); ctFonts.asciiTheme = ST_Theme.minorHAnsi; ctFonts.eastAsiaTheme = ST_Theme.minorHAnsi; ctFonts.hAnsiTheme = ST_Theme.minorHAnsi; ctFonts.cstheme = ST_Theme.minorBidi; ctRpr.AddNewB().val = ST_OnOff.off; ctRpr.AddNewBCs().val = ST_OnOff.off; ctRpr.AddNewColor().val = "auto"; ctRpr.AddNewSz().val = 24UL; ctRpr.AddNewSzCs().val = 24UL; CT_P ctP = block.AddNewSdtContent().AddNewP(); byte[] bytes = Encoding.Unicode.GetBytes("00EF7E24"); ctP.rsidR = bytes; ctP.rsidRDefault = bytes; ctP.AddNewPPr().AddNewPStyle().val = "TOCHeading"; ctP.AddNewR().AddNewT().Value = "Table of Contents"; }
public TOC(CT_SdtBlock block) { this.block = block; CT_SdtPr sdtPr = block.AddNewSdtPr(); CT_DecimalNumber id = sdtPr.AddNewId(); id.val = ("4844945"); sdtPr.AddNewDocPartObj().AddNewDocPartGallery().val = ("Table of Contents"); CT_SdtEndPr sdtEndPr = block.AddNewSdtEndPr(); CT_RPr rPr = sdtEndPr.AddNewRPr(); CT_Fonts fonts = rPr.AddNewRFonts(); fonts.asciiTheme = (ST_Theme.minorHAnsi); fonts.eastAsiaTheme = (ST_Theme.minorHAnsi); fonts.hAnsiTheme = (ST_Theme.minorHAnsi); fonts.cstheme = (ST_Theme.minorBidi); CT_SdtContentBlock content = block.AddNewSdtContent(); CT_P p = content.AddNewP(); byte[] b = Encoding.Unicode.GetBytes("00EF7E24"); p.rsidR = b; p.rsidRDefault = b; CT_PPr pPr = p.AddNewPPr(); pPr.AddNewPStyle().val = ("TOCHeading"); pPr.AddNewJc().val = ST_Jc.center; CT_R run = p.AddNewR(); run.AddNewRPr().AddNewSz().val = 48; run.AddNewT().Value = ("Table of Contents"); run.AddNewBr().type = ST_BrType.textWrapping; // line break // TOC Field p = content.AddNewP(); pPr = p.AddNewPPr(); pPr.AddNewPStyle().val = "TOC1"; pPr.AddNewRPr().AddNewNoProof(); run = p.AddNewR(); run.AddNewFldChar().fldCharType = ST_FldCharType.begin; run = p.AddNewR(); CT_Text text = run.AddNewInstrText(); text.space = "preserve"; text.Value = (" TOC \\h \\z "); p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate; }
private static void CreateFooter(XWPFDocument doc, string headerText, string imageUrl = null) { if (doc.Document.body.sectPr == null) { doc.Document.body.sectPr = new CT_SectPr(); } CT_SectPr m_SectPr = doc.Document.body.sectPr; CT_Ftr footer = new CT_Ftr(); CT_SdtBlock sdtBlock = new CT_SdtBlock(); CT_SdtPr sdtPr = sdtBlock.AddNewSdtPr(); CT_SdtDocPart sdtDocPart = sdtPr.AddNewDocPartObj(); sdtDocPart.AddNewDocPartGallery().val = "Page Numbers (Bottom of Page)"; sdtDocPart.docPartUnique = new CT_OnOff(); CT_SdtContentBlock sdtContentBlock = sdtBlock.AddNewSdtContent(); CT_P p = sdtContentBlock.AddNewP(); p.AddNewPPr().AddNewJc().val = ST_Jc.center; p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin; p.AddNewR().AddNewInstrText().Value = "PAGE"; p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate; p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end; p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.begin; p.AddNewR().AddNewInstrText().Value = "NUMPAGES"; p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.separate; p.AddNewR().AddNewFldChar().fldCharType = ST_FldCharType.end; footer.Items.Add(sdtBlock); XWPFRelation Hrelation = XWPFRelation.FOOTER; XWPFFooter xwpfFooter = (XWPFFooter)doc.CreateRelationship(Hrelation, XWPFFactory.GetInstance(), doc.FooterList.Count); xwpfFooter.SetXWPFDocument(doc); xwpfFooter.SetHeaderFooter(footer); CT_HdrFtrRef m_HdrFtr2 = m_SectPr.AddNewFooterReference(); m_HdrFtr2.type = ST_HdrFtr.@default; m_HdrFtr2.id = xwpfFooter.GetPackageRelationship().Id; }
/// <summary> /// 创建页眉页脚 /// </summary> /// <param name="doc"></param> private void CreatePageHeaderFooter(XWPFDocument doc, CT_SectPr m_Sectpr) { XWPFParagraph p1 = doc.CreateParagraph(); p1.CreateRun().AddBreak();//新建页 //创建页眉 CT_Hdr m_hdr = new CT_Hdr(); m_hdr.Items = new System.Collections.ArrayList(); CT_P m_p = m_hdr.AddNewP(); CT_PPr cT_PPr = m_p.AddNewPPr(); cT_PPr.AddNewJc().val = ST_Jc.both;//两端对齐 cT_PPr.AddNewSpacing().beforeLines = "370"; CT_R cT_R = m_p.AddNewR(); cT_R.AddNewT().Value = "110kV濂泉(沙河)送电线路工程 施工图设计说明书 S123456S-D0101-01";//页眉内容 CT_RPr cT_RPr = cT_R.AddNewRPr(); cT_RPr.AddNewSz().val = (ulong)18; cT_RPr.AddNewSzCs().val = (ulong)18; cT_RPr.AddNewRFonts().ascii = "宋体"; //cT_RPr.AddNewU().val=ST_Underline.single;//下划线 //创建页眉关系(headern.xml) XWPFRelation Hrelation = XWPFRelation.HEADER; XWPFHeader m_h = (XWPFHeader)doc.CreateRelationship(Hrelation, XWPFFactory.GetInstance(), 3); //doc.CreateFootnotes(); //设置页眉 m_h.SetHeaderFooter(m_hdr); CT_HdrFtrRef m_HdrFtr = m_Sectpr.AddNewHeaderReference(); m_HdrFtr.type = ST_HdrFtr.@default; //m_h.GetRelationById(m_HdrFtr.id); m_HdrFtr.id = m_h.GetPackageRelationship().Id; //创建页脚 CT_Ftr m_ftr = new CT_Ftr(); m_ftr.Items = new System.Collections.ArrayList(); CT_SdtBlock m_Sdt = new CT_SdtBlock(); CT_SdtPr m_SdtPr = m_Sdt.AddNewSdtPr(); CT_SdtDocPart m_SdDocPartObj = m_SdtPr.AddNewDocPartObj(); m_SdDocPartObj.AddNewDocPartGallery().val = "PageNumbers (Bottom of Page)"; m_SdDocPartObj.docPartUnique = new CT_OnOff(); CT_SdtContentBlock m_SdtContent = m_Sdt.AddNewSdtContent(); CT_P m_SdtContentP = m_SdtContent.AddNewP(); CT_PPr m_SdtContentPpr = m_SdtContentP.AddNewPPr(); m_SdtContentPpr.AddNewJc().val = ST_Jc.center; m_SdtContentP.Items = new System.Collections.ArrayList(); CT_SimpleField m_fldSimple = new CT_SimpleField(); m_fldSimple.instr = " PAGE \\*MERGEFORMAT"; //页码字体大小 CT_R m_r = new CT_R(); CT_RPr m_Rpr = m_r.AddNewRPr(); m_Rpr.AddNewRFonts().ascii = "宋体"; m_Rpr.AddNewSz().val = (ulong)18; m_Rpr.AddNewSzCs().val = (ulong)18; m_r.AddNewT().Value = "1";//页数 m_fldSimple.Items.Add(m_r); m_SdtContentP.Items.Add(m_fldSimple); m_ftr.Items.Add(m_Sdt); //m_ftr.AddNewP().AddNewR().AddNewT().Value = "fff";//页脚内容 //m_ftr.AddNewP().AddNewPPr().AddNewJc().val = ST_Jc.center; //创建页脚关系(footern.xml) XWPFRelation Frelation = XWPFRelation.FOOTER; XWPFFooter m_f = (XWPFFooter)doc.CreateRelationship(Frelation, XWPFFactory.GetInstance(), doc.FooterList.Count + 1); //设置页脚 m_f.SetHeaderFooter(m_ftr); m_HdrFtr = m_Sectpr.AddNewFooterReference(); m_HdrFtr.type = ST_HdrFtr.@default; m_HdrFtr.id = m_f.GetPackageRelationship().Id; }