示例#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);
         }
     }
 }
示例#2
0
 private void Init()
 {
     //copied from XWPFDocument...should centralize this code
     //to avoid duplication
     foreach (object o in ctFtnEdn.Items)
     {
         if (o is CT_P)
         {
             XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
             bodyElements.Add(p);
             paragraphs.Add(p);
         }
         else if (o is CT_Tbl)
         {
             XWPFTable t = new XWPFTable((CT_Tbl)o, this);
             bodyElements.Add(t);
             tables.Add(t);
         }
         else if (o is CT_SdtBlock)
         {
             XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
             bodyElements.Add(c);
         }
     }
 }
示例#3
0
        private List <AbstractXWPFSDT> ExtractSDTsFromBodyElements(IList <IBodyElement> elements)
        {
            List <AbstractXWPFSDT> sdts = new List <AbstractXWPFSDT>();

            foreach (IBodyElement e in elements)
            {
                if (e is XWPFSDT)
                {
                    XWPFSDT sdt = (XWPFSDT)e;
                    sdts.Add(sdt);
                }
                else if (e is XWPFParagraph)
                {
                    XWPFParagraph p = (XWPFParagraph)e;
                    foreach (IRunElement e2 in p.IRuns)
                    {
                        if (e2 is XWPFSDT)
                        {
                            XWPFSDT sdt = (XWPFSDT)e2;
                            sdts.Add(sdt);
                        }
                    }
                }
                else if (e is XWPFTable)
                {
                    XWPFTable table = (XWPFTable)e;
                    sdts.AddRange(ExtractSDTsFromTable(table));
                }
            }
            return(sdts);
        }
示例#4
0
        /**
         * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
         */

        public XWPFTableCell(CT_Tc cell, XWPFTableRow tableRow, IBody part)
        {
            this.ctTc     = cell;
            this.part     = part;
            this.tableRow = tableRow;
            // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
            if (cell.GetPList().Count < 1)
            {
                cell.AddNewP();
            }
            bodyElements = new List <IBodyElement>();
            paragraphs   = new List <XWPFParagraph>();
            tables       = new List <XWPFTable>();
            foreach (object o in ctTc.Items)
            {
                if (o is CT_P)
                {
                    XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                    paragraphs.Add(p);
                    bodyElements.Add(p);
                }
                if (o is CT_Tbl)
                {
                    XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                    tables.Add(t);
                    bodyElements.Add(t);
                }
                if (o is CT_SdtBlock)
                {
                    XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
                    bodyElements.Add(c);
                }
                if (o is CT_SdtRun)
                {
                    XWPFSDT c = new XWPFSDT((CT_SdtRun)o, this);
                    bodyElements.Add(c);
                }
            }
        }
示例#5
0
        internal override void OnDocumentRead()
        {
            base.OnDocumentRead();
            FtrDocument ftrDocument = null;

            try
            {
                XDocument xmldoc = ConvertStreamToXml(GetPackagePart().GetInputStream());
                ftrDocument  = FtrDocument.Parse(xmldoc, NamespaceManager);
                headerFooter = ftrDocument.Ftr;
                // parse the document with cursor and add
                // the XmlObject to its lists
                foreach (object o in headerFooter.Items)
                {
                    if (o is CT_P)
                    {
                        XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                        paragraphs.Add(p);
                        bodyElements.Add(p);
                    }
                    if (o is CT_Tbl)
                    {
                        XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                        tables.Add(t);
                        bodyElements.Add(t);
                    }
                    if (o is CT_SdtBlock)
                    {
                        XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
                        bodyElements.Add(c);
                    }
                }
            }
            catch (Exception e)
            {
                throw new POIXMLException(e);
            }
        }
示例#6
0
        /// <summary>
        /// Read the document
        /// </summary>
        internal override void OnDocumentRead()
        {
            base.OnDocumentRead();
            HdrDocument hdrDocument = null;

            try
            {
                XDocument xmldoc = DocumentHelper.LoadDocument(GetPackagePart().GetInputStream());
                hdrDocument  = HdrDocument.Parse(xmldoc, NamespaceManager);
                headerFooter = hdrDocument.Hdr;
                foreach (object o in headerFooter.Items)
                {
                    if (o is CT_P)
                    {
                        XWPFParagraph p = new XWPFParagraph((CT_P)o, this);
                        paragraphs.Add(p);
                        bodyElements.Add(p);
                    }
                    if (o is CT_Tbl)
                    {
                        XWPFTable t = new XWPFTable((CT_Tbl)o, this);
                        tables.Add(t);
                        bodyElements.Add(t);
                    }
                    if (o is CT_SdtBlock)
                    {
                        XWPFSDT c = new XWPFSDT((CT_SdtBlock)o, this);
                        bodyElements.Add(c);
                    }
                }
            }
            catch (Exception e)
            {
                throw new POIXMLException(e);
            }
        }