Beispiel #1
0
 public XWPFSDTContent(CT_SdtContentBlock block, IBody part, IRunBody parent)
 {
     
     foreach (object o in block.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, part);
             bodyElements.Add(p);
             paragraphs.Add(p);
         }
         else if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, part);
             bodyElements.Add(t);
             tables.Add(t);
         }
         else if (o is CT_SdtBlock)
         {
             XWPFSDT c = new XWPFSDT(((CT_SdtBlock)o), part);
             bodyElements.Add(c);
             contentControls.Add(c);
         }
         else if (o is CT_R)
         {
             XWPFRun run = new XWPFRun((CT_R)o, parent);
             runs.Add(run);
             bodyElements.Add(run);
         }
     }
 }
Beispiel #2
0
 public XWPFSDTContent(CT_SdtContentBlock block, IBody part, IRunBody parent)
 {
     foreach (object o in block.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, part);
             bodyElements.Add(p);
             paragraphs.Add(p);
         }
         else if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, part);
             bodyElements.Add(t);
             tables.Add(t);
         }
         else if (o is CT_SdtBlock)
         {
             XWPFSDT c = new XWPFSDT(((CT_SdtBlock)o), part);
             bodyElements.Add(c);
             contentControls.Add(c);
         }
         else if (o is CT_R)
         {
             XWPFRun run = new XWPFRun((CT_R)o, parent);
             runs.Add(run);
             bodyElements.Add(run);
         }
     }
 }
Beispiel #3
0
        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");
        }
Beispiel #4
0
        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;
        }
Beispiel #5
0
        public void AddRow(int level, String title, int page, String bookmarkRef)
        {
            CT_SdtContentBlock contentBlock = this.block.sdtContent;
            CT_P p = contentBlock.AddNewP();

            byte[] b = Encoding.Unicode.GetBytes("00EF7E24");
            p.rsidR        = b;
            p.rsidRDefault = b;
            CT_PPr pPr = p.AddNewPPr();

            pPr.AddNewPStyle().val = ("TOC" + level);
            CT_Tabs    tabs        = pPr.AddNewTabs();
            CT_TabStop tab         = tabs.AddNewTab();

            tab.val    = (ST_TabJc.right);
            tab.leader = (ST_TabTlc.dot);
            tab.pos    = "8290"; //(new BigInteger("8290"));
            pPr.AddNewRPr().AddNewNoProof();
            CT_R Run = p.AddNewR();

            Run.AddNewRPr().AddNewNoProof();
            Run.AddNewT().Value = (title);
            Run = p.AddNewR();
            Run.AddNewRPr().AddNewNoProof();
            Run.AddNewTab();
            Run = p.AddNewR();
            Run.AddNewRPr().AddNewNoProof();
            Run.AddNewFldChar().fldCharType = (ST_FldCharType.begin);
            // pageref run
            Run = p.AddNewR();
            Run.AddNewRPr().AddNewNoProof();
            CT_Text text = Run.AddNewInstrText();

            text.space = "preserve";// (Space.PRESERVE);
            // bookmark reference
            text.Value = (" PAGEREF _Toc" + bookmarkRef + " \\h ");
            p.AddNewR().AddNewRPr().AddNewNoProof();
            Run = p.AddNewR();
            Run.AddNewRPr().AddNewNoProof();
            Run.AddNewFldChar().fldCharType = (ST_FldCharType.separate);
            // page number run
            Run = p.AddNewR();
            Run.AddNewRPr().AddNewNoProof();
            Run.AddNewT().Value = page.ToString();
            Run = p.AddNewR();
            Run.AddNewRPr().AddNewNoProof();
            Run.AddNewFldChar().fldCharType = (ST_FldCharType.end);
        }
Beispiel #6
0
        public CT_SdtBlock Build()
        {
            // append end field char for TOC - only once
            if (!isBuilt)
            {
                CT_SdtContentBlock contentBlock = block.sdtContent;
                CT_P p   = contentBlock.AddNewP();
                CT_R run = p.AddNewR();
                run.AddNewRPr().AddNewNoProof();
                run.AddNewFldChar().fldCharType = ST_FldCharType.end;

                isBuilt = true;
            }

            return(block);
        }
Beispiel #7
0
        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;
        }
Beispiel #8
0
        /// <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;
        }