Exemplo n.º 1
0
        public void Bug57495_getParagraphArrayInTableCell()
        {
            XWPFDocument doc = new XWPFDocument();
            //let's create a table for the test
            XWPFTable table = doc.CreateTable(2, 2);

            Assert.IsNotNull(table);
            XWPFParagraph p = table.GetRow(0).GetCell(0).GetParagraphArray(0);

            Assert.IsNotNull(p);
            //let's check also that returns the correct paragraph
            XWPFParagraph same = table.GetRow(0).GetCell(0).Paragraphs[0];

            Assert.AreEqual(p, same);
        }
Exemplo n.º 2
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().Value;
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the TableCell which belongs to the TableCell
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public XWPFTableCell GetTableCell(CT_Tc cell)
        {
            object obj = cell.Parent;

            if (!(obj is CT_Row))
            {
                return(null);
            }

            CT_Row row = (CT_Row)obj;

            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 (row == null)
            {
                return(null);
            }
            return(tableRow.GetTableCell(cell));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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 tr = table.GetRow(row);

            if (tr == null)
            {
                return(null);
            }
            return(tr.GetTableCell(cell));
        }
Exemplo n.º 6
0
        public void TestCreateRow()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();
            CT_Row r1 = table.AddNewTr();
            r1.AddNewTc().AddNewP();
            r1.AddNewTc().AddNewP();
            CT_Row r2 = table.AddNewTr();
            r2.AddNewTc().AddNewP();
            r2.AddNewTc().AddNewP();
            CT_Row r3 = table.AddNewTr();
            r3.AddNewTc().AddNewP();
            r3.AddNewTc().AddNewP();

            XWPFTable xtab = new XWPFTable(table, doc);
            Assert.AreEqual(3, xtab.NumberOfRows);
            Assert.IsNotNull(xtab.GetRow(2));

            //add a new row
            xtab.CreateRow();
            Assert.AreEqual(4, xtab.NumberOfRows);

            //check number of cols
            Assert.AreEqual(2, table.GetTrArray(0).SizeOfTcArray());

            //check creation of first row
            xtab = new XWPFTable(new CT_Tbl(), doc);
            Assert.AreEqual(1, xtab.GetCTTbl().GetTrArray(0).SizeOfTcArray());
        }
Exemplo n.º 7
0
        public void TestCreateRow()
        {
            XWPFDocument doc = new XWPFDocument();

            CT_Tbl table = new CT_Tbl();
            CT_Row r1    = table.AddNewTr();

            r1.AddNewTc().AddNewP();
            r1.AddNewTc().AddNewP();
            CT_Row r2 = table.AddNewTr();

            r2.AddNewTc().AddNewP();
            r2.AddNewTc().AddNewP();
            CT_Row r3 = table.AddNewTr();

            r3.AddNewTc().AddNewP();
            r3.AddNewTc().AddNewP();

            XWPFTable xtab = new XWPFTable(table, doc);

            Assert.AreEqual(3, xtab.GetNumberOfRows());
            Assert.IsNotNull(xtab.GetRow(2));

            //add a new row
            xtab.CreateRow();
            Assert.AreEqual(4, xtab.GetNumberOfRows());

            //check number of cols
            Assert.AreEqual(2, table.GetTrArray(0).SizeOfTcArray());

            //check creation of first row
            xtab = new XWPFTable(new CT_Tbl(), doc);
            Assert.AreEqual(1, xtab.GetCTTbl().GetTrArray(0).SizeOfTcArray());
        }
        private void SetHeadings(ref XWPFDocument doc, XWPFTable table)
        {
            XWPFParagraph p1 = doc.CreateParagraph();
            XWPFRun r1 = p1.CreateRun();
            r1.SetBold(true);
            r1.SetText("Category");
            r1.SetBold(true);
            r1.SetFontFamily("Courier");
            table.GetRow(0).GetCell(0).SetParagraph(p1);

            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetBold(true);
            r2.SetText("Category");
            r2.SetBold(true);
            r2.SetFontFamily("Courier");
            table.GetRow(0).GetCell(1).SetParagraph(p2);


        }
Exemplo n.º 9
0
        public void TestSetGetCantSplitRow()
        {
            // 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.IsCantSplitRow = true;
            bool isCant = tr.IsCantSplitRow;
            //assert(isCant);
            Assert.IsTrue(isCant);
        }
Exemplo n.º 10
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.SetRepeatHeader(true);
            bool isRpt = tr.IsRepeatHeader();
            //assert(isRpt);
            Assert.IsTrue(isRpt);
        }
Exemplo n.º 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);
        }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
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.IsTrue(isRpt);
        }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
0
        public void TestSetGetCantSplitRow()
        {
            // 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.SetCantSplitRow(true);
            bool isCant = tr.IsCantSplitRow();

            //assert(isCant);
            Assert.IsTrue(isCant);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 获取节点中表的信息
        /// </summary>
        /// <param name="table">table</param>
        private TableInfo GetTable(XWPFTable table)
        {
            try
            {
                TableInfo mTable = new TableInfo();
                List<ColumnInfo> list = new List<ColumnInfo>();
                List<PkKeyInfo> listPkKeyInfo = new List<PkKeyInfo>();
                mTable.ListColumnInfo = list;
                mTable.ListPkKeyInfo = listPkKeyInfo;
                //表的ID
                mTable.TableObjectID = Guid.NewGuid().ToString();
                //表的中文名称
                mTable.Name = table.GetRow(0).GetCell(1).GetText().Trim();
                //表的英文名称
                mTable.Code = table.GetRow(1).GetCell(1).GetText().Trim();
                //表的描述
                mTable.Comment = mTable.Name;

                //标题列
                var row = table.GetRow(3);
                //缓存列索引和名称
                Dictionary<int, string> dic = new Dictionary<int, string>();
                int i = 0;
                foreach (var cell in row.GetTableCells())
                {
                    dic.Add(i, cell.GetText().Trim());
                    i++;
                }

                int iRow = 4;
                row = table.GetRow(iRow);
                while (row != null)
                {
                    InitColumns(row, dic, mTable);
                    iRow = iRow + 1;
                    row = table.GetRow(iRow);
                }

                if (string.IsNullOrEmpty(mTable.Comment))
                {
                    mTable.Comment = mTable.Name;
                }
                if (mTable.ListPkKeyInfo != null && mTable.ListPkKeyInfo.Count > 0)
                {
                    foreach (PkKeyInfo pkInfo in mTable.ListPkKeyInfo)
                    {
                        mTable.PkKeyNameList = mTable.PkKeyNameList + pkInfo.Name + ",";
                    }
                }
                if (!string.IsNullOrEmpty(mTable.PkKeyNameList))
                {
                    mTable.PkKeyNameList = mTable.PkKeyNameList.Substring(0, mTable.PkKeyNameList.Length - 1);
                }
                return mTable;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }