예제 #1
0
        public void TestTblGrid()
        {
            XWPFDocument doc       = new XWPFDocument();
            CT_Tbl       ctTable   = new CT_Tbl();
            CT_TblGrid   cttblgrid = ctTable.AddNewTblGrid();

            cttblgrid.AddNewGridCol().w = 123;
            cttblgrid.AddNewGridCol().w = 321;

            XWPFTable xtab = new XWPFTable(ctTable, doc);

            Assert.AreEqual(123, xtab.GetCTTbl().tblGrid.gridCol[0].w);
            Assert.AreEqual(321, xtab.GetCTTbl().tblGrid.gridCol[1].w);
        }
예제 #2
0
        /**
         * inserts an existing XWPFTable to the arrays bodyElements and tables
         * @see Npoi.Core.XWPF.UserModel.IBody#insertTable(int, Npoi.Core.XWPF.UserModel.XWPFTable)
         */

        public void InsertTable(int pos, XWPFTable table)
        {
            bodyElements.Insert(pos, table);
            int i;

            for (i = 0; i < ctTc.GetTblList().Count; i++)
            {
                CT_Tbl tbl = ctTc.GetTblArray(i);
                if (tbl == table.GetCTTbl())
                {
                    break;
                }
            }
            tables.Insert(i, table);
        }
예제 #3
0
        public void TestSetGetWidth()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();

            table.AddNewTblPr().AddNewTblW().w = "1000";

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual(1000, xtab.Width);

            xtab.Width = 100;
            Assert.AreEqual(100, int.Parse(table.tblPr.tblW.w));
        }
예제 #4
0
        public void TestGetText()
        {
            XWPFDocument doc       = new XWPFDocument();
            CT_Tbl       table     = new CT_Tbl();
            CT_Row       row       = table.AddNewTr();
            CT_Tc        cell      = row.AddNewTc();
            CT_P         paragraph = cell.AddNewP();
            CT_R         run       = paragraph.AddNewR();
            CT_Text      text      = run.AddNewT();

            text.Value = ("finally I can Write!");

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual("finally I can Write!\n", xtab.Text);
        }
예제 #5
0
        public void Test54099()
        {
            XWPFDocument  doc     = new XWPFDocument();
            CT_Tbl        ctTable = new CT_Tbl();
            XWPFTable     table   = new XWPFTable(ctTable, doc);
            XWPFTableRow  tr      = table.GetRow(0);
            XWPFTableCell cell    = tr.GetCell(0);

            CT_Tc     ctTc   = cell.GetCTTc();
            CT_TcPr   tcPr   = ctTc.AddNewTcPr();
            CT_HMerge hMerge = tcPr.AddNewHMerge();

            hMerge.val = (ST_Merge.restart);

            CT_TcBorders tblBorders = tcPr.AddNewTcBorders();
            CT_VMerge    vMerge     = tcPr.AddNewVMerge();
        }
예제 #6
0
        public void TestSetGetRepeatHeader()
        {
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);

            Assert.IsNotNull(tr);

            tr.IsRepeatHeader = true;
            bool isRpt = tr.IsRepeatHeader;

            //assert(isRpt);
            Assert.IsTrue(isRpt);
        }
예제 #7
0
        public void TestConstructor()
        {
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    xtab    = new XWPFTable(ctTable, doc);

            Assert.IsNotNull(xtab);
            Assert.AreEqual(1, ctTable.SizeOfTrArray());
            Assert.AreEqual(1, ctTable.GetTrArray(0).SizeOfTcArray());
            Assert.IsNotNull(ctTable.GetTrArray(0).GetTcArray(0).GetPArray(0));

            ctTable = new CT_Tbl();
            xtab    = new XWPFTable(ctTable, doc, 3, 2);
            Assert.IsNotNull(xtab);
            Assert.AreEqual(3, ctTable.SizeOfTrArray());
            Assert.AreEqual(2, ctTable.GetTrArray(0).SizeOfTcArray());
            Assert.IsNotNull(ctTable.GetTrArray(0).GetTcArray(0).GetPArray(0));
        }
예제 #8
0
        public void TestSetGetColor()
        {
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);
            // table has a single row by default; grab it
            XWPFTableRow tr = table.GetRow(0);

            Assert.IsNotNull(tr);
            // row has a single cell by default; grab it
            XWPFTableCell cell = tr.GetCell(0);

            cell.SetColor("F0000F");
            String clr = cell.GetColor();

            Assert.AreEqual("F0000F", clr);
        }
예제 #9
0
        public void ReadHdrFtr()
        {
            bodyElements = new List <IBodyElement>();
            paragraphs   = new List <XWPFParagraph>();
            tables       = new List <XWPFTable>();
            // 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);
                }
            }

            /*XmlCursor cursor = headerFooter.NewCursor();
             * cursor.SelectPath("./*");
             * while (cursor.ToNextSelection())
             * {
             *  XmlObject o = cursor.Object;
             *  if (o is CTP)
             *  {
             *      XWPFParagraph p = new XWPFParagraph((CTP)o, this);
             *      paragraphs.Add(p);
             *      bodyElements.Add(p);
             *  }
             *  if (o is CTTbl)
             *  {
             *      XWPFTable t = new XWPFTable((CTTbl)o, this);
             *      tables.Add(t);
             *      bodyElements.Add(t);
             *  }
             * }
             * cursor.Dispose();*/
        }
예제 #10
0
        private List <AbstractXWPFSDT> ExtractSDTsFromTable(XWPFTable table)
        {
            List <AbstractXWPFSDT> sdts = new List <AbstractXWPFSDT>();

            foreach (XWPFTableRow r in table.Rows)
            {
                foreach (ICell c in r.GetTableICells())
                {
                    if (c is XWPFSDTCell)
                    {
                        sdts.Add((XWPFSDTCell)c);
                    }
                    else if (c is XWPFTableCell)
                    {
                        sdts.AddRange(ExtractSDTsFromBodyElements(((XWPFTableCell)c).BodyElements));
                    }
                }
            }
            return(sdts);
        }
예제 #11
0
        private void AppendBodyElementText(StringBuilder text, IBodyElement e, bool isLast)
        {
            if (e is XWPFParagraph)
            {
                text.Append(((XWPFParagraph)e).Text);
                if (isLast == false)
                {
                    text.Append('\t');
                }
            }
            else if (e is XWPFTable)
            {
                XWPFTable eTable = (XWPFTable)e;
                foreach (XWPFTableRow row in eTable.Rows)
                {
                    foreach (XWPFTableCell cell in row.GetTableCells())
                    {
                        IList <IBodyElement> localBodyElements = cell.BodyElements;
                        for (int i = 0; i < localBodyElements.Count; i++)
                        {
                            bool localIsLast = (i == localBodyElements.Count - 1) ? true : false;
                            AppendBodyElementText(text, localBodyElements[i], localIsLast);
                        }
                    }
                }

                if (isLast == false)
                {
                    text.Append('\n');
                }
            }
            else if (e is XWPFSDT)
            {
                text.Append(((XWPFSDT)e).Content.Text);
                if (isLast == false)
                {
                    text.Append('\t');
                }
            }
        }
예제 #12
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);
                }
            }
        }
예제 #13
0
        public void TestSetGetVBorders()
        {
            // create a table
            XWPFDocument doc     = new XWPFDocument();
            CT_Tbl       ctTable = new CT_Tbl();
            XWPFTable    table   = new XWPFTable(ctTable, doc);

            // Set inside vertical border
            table.SetInsideVBorder(Npoi.Core.XWPF.UserModel.XWPFTable.XWPFBorderType.DOUBLE, 4, 0, "00FF00");
            // Get inside vertical border components
            Npoi.Core.XWPF.UserModel.XWPFTable.XWPFBorderType bt = table.InsideVBorderType;
            Assert.AreEqual(Npoi.Core.XWPF.UserModel.XWPFTable.XWPFBorderType.DOUBLE, bt);
            int sz = table.InsideVBorderSize;

            Assert.AreEqual(4, sz);
            int sp = table.InsideVBorderSpace;

            Assert.AreEqual(0, sp);
            String clr = table.InsideVBorderColor;

            Assert.AreEqual("00FF00", clr);
        }
예제 #14
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);
            }
        }
예제 #15
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);
            }
        }
예제 #16
0
 public XWPFTableRow(CT_Row row, XWPFTable table)
 {
     this.table = table;
     this.ctRow = row;
     GetTableCells();
 }