示例#1
0
        public void TestSetGetVertAlignment()
        {
            // instantiate the following classes so they'll Get picked up by
            // the XmlBean process and Added to the jar file. they are required
            // for the following XWPFTableCell methods.
            CT_Shd ctShd = new CT_Shd();

            Assert.IsNotNull(ctShd);
            CT_VerticalJc ctVjc = new CT_VerticalJc();

            Assert.IsNotNull(ctVjc);
            ST_Shd stShd = ST_Shd.nil;

            Assert.IsNotNull(stShd);
            ST_VerticalJc stVjc = ST_VerticalJc.top;

            Assert.IsNotNull(stVjc);

            // 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.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.BOTH);
            XWPFTableCell.XWPFVertAlign al = cell.GetVerticalAlignment();
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
示例#2
0
        /**
         * Get the TableCell which belongs to the TableCell
         */

        public XWPFTableCell GetTableCell(CT_Tc cell)
        {
            if (!(cell.Parent is CT_Row))
            {
                return(null);
            }
            CT_Row row = (CT_Row)cell.Parent;

            if (!(row.Parent is CT_Tbl))
            {
                return(null);
            }
            CT_Tbl    tbl   = (CT_Tbl)row.Parent;
            XWPFTable table = GetTable(tbl);

            if (table == null)
            {
                return(null);
            }
            XWPFTableRow tableRow = table.GetRow(row);

            if (tableRow == null)
            {
                return(null);
            }
            return(tableRow.GetTableCell(cell));
        }
示例#3
0
 private void AddColumn(XWPFTableRow tabRow, int sizeCol)
 {
     if (sizeCol > 0)
     {
         for (int i = 0; i < sizeCol; i++)
         {
             tabRow.CreateCell();
         }
     }
 }
示例#4
0
        /**
         * create a new XWPFTableRow object with as many cells as the number of columns defined in that moment
         *
         * @return tableRow
         */
        public XWPFTableRow CreateRow()
        {
            int sizeCol = ctTbl.SizeOfTrArray() > 0 ? ctTbl.GetTrArray(0)
                          .SizeOfTcArray() : 0;
            XWPFTableRow tabRow = new XWPFTableRow(ctTbl.AddNewTr(), this);

            AddColumn(tabRow, sizeCol);
            tableRows.Add(tabRow);
            return(tabRow);
        }
示例#5
0
 /**
  * inserts a new tablerow
  * @param pos
  * @return  the inserted row
  */
 public XWPFTableRow InsertNewTableRow(int pos)
 {
     if (pos >= 0 && pos <= tableRows.Count)
     {
         CT_Row       row      = ctTbl.InsertNewTr(pos);
         XWPFTableRow tableRow = new XWPFTableRow(row, this);
         tableRows.Insert(pos, tableRow);
         return(tableRow);
     }
     return(null);
 }
示例#6
0
 /**
  * add a new Row to the table
  * at position pos
  * @param row	the row which should be Added
  */
 public bool AddRow(XWPFTableRow row, int pos)
 {
     if (pos >= 0 && pos <= tableRows.Count)
     {
         ctTbl.InsertNewTr(pos);
         ctTbl.SetTrArray(pos, row.GetCTRow());
         tableRows.Insert(pos, row);
         return(true);
     }
     return(false);
 }
示例#7
0
        public void TestSetGetHeight()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();

            XWPFTable    xtab = new XWPFTable(table, doc);
            XWPFTableRow row  = xtab.CreateRow();

            row.Height = (20);
            Assert.AreEqual(20, row.Height);
        }
示例#8
0
 /**
  * add a new column for each row in this table
  */
 public void AddNewCol()
 {
     if (ctTbl.SizeOfTrArray() == 0)
     {
         CreateRow();
     }
     for (int i = 0; i < ctTbl.SizeOfTrArray(); i++)
     {
         XWPFTableRow tabRow = new XWPFTableRow(ctTbl.GetTrArray(i), this);
         tabRow.CreateCell();
     }
 }
示例#9
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);
        }
示例#10
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();
        }
示例#11
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);
        }
示例#12
0
        public XWPFTable(CT_Tbl table, IBody part, int row, int col)
            : this(table, part)
        {
            CT_TblGrid ctTblGrid = table.AddNewTblGrid();

            for (int j = 0; j < col; j++)
            {
                CT_TblGridCol ctGridCol = ctTblGrid.AddNewGridCol();
                ctGridCol.w = 300;
            }
            for (int i = 0; i < row; i++)
            {
                XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i);
                for (int k = 0; k < col; k++)
                {
                    if (tabRow.GetCell(k) == null)
                    {
                        tabRow.CreateCell();
                    }
                }
            }
        }
示例#13
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);
                }
            }
        }
示例#14
0
        public XWPFTable(CT_Tbl table, IBody part)
        {
            this.part  = part;
            this.ctTbl = table;

            tableRows = new List <XWPFTableRow>();
            // is an empty table: I add one row and one column as default
            if (table.SizeOfTrArray() == 0)
            {
                CreateEmptyTable(table);
            }

            foreach (CT_Row row in table.GetTrList())
            {
                StringBuilder rowText = new StringBuilder();
                row.Table = table;
                XWPFTableRow tabRow = new XWPFTableRow(row, this);
                tableRows.Add(tabRow);
                foreach (CT_Tc cell in row.GetTcList())
                {
                    foreach (CT_P ctp in cell.GetPList())
                    {
                        XWPFParagraph p = new XWPFParagraph(ctp, part);
                        if (rowText.Length > 0)
                        {
                            rowText.Append('\t');
                        }
                        rowText.Append(p.Text);
                    }
                }
                if (rowText.Length > 0)
                {
                    this.text.Append(rowText);
                    this.text.Append('\n');
                }
            }
        }
示例#15
0
        public XWPFSDTContentCell(CT_SdtContentCell sdtContentCell,
                                  XWPFTableRow xwpfTableRow, IBody part)
        {
            StringBuilder sb = new StringBuilder();

            //keep track of the following,
            //and add "\n" only before the start of a body
            //element if it is not the first body element.

            //index of cell in row
            int tcCnt = 0;
            //count of body objects
            int    iBodyCnt = 0;
            int    depth    = 1;
            string sdtXml   = sdtContentCell.ToString();

            using (StringReader sr = new StringReader(sdtXml))
            {
                XmlParserContext context = new XmlParserContext(null, POIXMLDocumentPart.NamespaceManager,
                                                                null, XmlSpace.Preserve);
                using (XmlReader cursor = XmlReader.Create(sr, null, context))
                {
                    while (cursor.Read() && depth > 0)
                    {
                        if (cursor.NodeType == XmlNodeType.Text)
                        {
                            sb.Append(cursor.ReadContentAsString());
                        }
                        else if (IsStartToken(cursor, "tr"))
                        {
                            tcCnt    = 0;
                            iBodyCnt = 0;
                        }
                        else if (IsStartToken(cursor, "tc"))
                        {
                            if (tcCnt++ > 0)
                            {
                                sb.Append("\t");
                            }
                            iBodyCnt = 0;
                        }
                        else if (IsStartToken(cursor, "p") ||
                                 IsStartToken(cursor, "tbl") ||
                                 IsStartToken(cursor, "sdt"))
                        {
                            if (iBodyCnt > 0)
                            {
                                sb.Append("\n");
                            }
                            iBodyCnt++;
                        }
                    }
                }
            }
            //IEnumerator cursor = sdtContentCell.Items.GetEnumerator();
            //while (cursor.MoveNext() && depth > 0)
            //{
            //    //TokenType t = cursor.ToNextToken();
            //    object t = cursor.Current;
            //    if (t is CT_Text)//??
            //    {
            //        //sb.Append(cursor.TextValue);
            //    }
            //    else if (IsStartToken(cursor, "tr"))
            //    {
            //        tcCnt = 0;
            //        iBodyCnt = 0;
            //    }
            //    else if (IsStartToken(cursor, "tc"))
            //    {
            //        if (tcCnt++ > 0)
            //        {
            //            sb.Append("\t");
            //        }
            //        iBodyCnt = 0;
            //    }
            //    else if (IsStartToken(cursor, "p") ||
            //          IsStartToken(cursor, "tbl") ||
            //          IsStartToken(cursor, "sdt"))
            //    {
            //        if (iBodyCnt > 0)
            //        {
            //            sb.Append("\n");
            //        }
            //        iBodyCnt++;
            //    }
            //    //if (cursor.IsStart())
            //    //{
            //    //    depth++;
            //    //}
            //    //else if (cursor.IsEnd())
            //    //{
            //    //    depth--;
            //    //}
            //}
            text = sb.ToString();
        }
示例#16
0
 public XWPFSDTCell(CT_SdtCell sdtCell, XWPFTableRow xwpfTableRow, IBody part)
     : base(sdtCell.sdtPr, part)
 {
     //base(sdtCell.SdtPr, part);
     cellContent = new XWPFSDTContentCell(sdtCell.sdtContent, xwpfTableRow, part);
 }
示例#17
0
 /**
  * add a new Row to the table
  *
  * @param row	the row which should be Added
  */
 public void AddRow(XWPFTableRow row)
 {
     ctTbl.AddNewTr();
     ctTbl.SetTrArray(this.NumberOfRows - 1, row.GetCTRow());
     tableRows.Add(row);
 }