예제 #1
0
        public void TestCreateTable()
        {
            // open an empty document
            XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("sample.docx");

            // create a table with 5 rows and 7 coloumns
            int       noRows = 5;
            int       noCols = 7;
            XWPFTable table  = doc.CreateTable(noRows, noCols);

            // assert the table is empty
            List <XWPFTableRow> rows = table.GetRows();

            Assert.AreEqual(noRows, rows.Count, "Table has less rows than requested.");
            foreach (XWPFTableRow xwpfRow in rows)
            {
                Assert.IsNotNull(xwpfRow);
                for (int i = 0; i < 7; i++)
                {
                    XWPFTableCell xwpfCell = xwpfRow.GetCell(i);
                    Assert.IsNotNull(xwpfCell);
                    Assert.AreEqual(1, xwpfCell.Paragraphs.Count, "Empty cells should not have one paragraph.");
                    xwpfCell = xwpfRow.GetCell(i);
                    Assert.AreEqual(1, xwpfCell.Paragraphs.Count, "Calling 'getCell' must not modify cells content.");
                }
            }
            doc.Package.Revert();
        }
예제 #2
0
        /**
         * create a new XWPFTableCell and add it to the tableCell-list of this tableRow
         * @return the newly Created XWPFTableCell
         */
        public XWPFTableCell CreateCell()
        {
            XWPFTableCell tableCell = new XWPFTableCell(ctRow.AddNewTc(), this, table.Body);

            tableCells.Add(tableCell);
            return(tableCell);
        }
예제 #3
0
 /**
  * Adds a new TableCell at the end of this tableRow
  */
 public XWPFTableCell AddNewTableCell()
 {
     CT_Tc cell = ctRow.AddNewTc();
     XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.Body);
     tableCells.Add(tableCell);
     return tableCell;
 }
예제 #4
0
        public void MergeCells(int startIndex, int endIndex)
        {
            if (startIndex >= endIndex)
            {
                throw new ArgumentOutOfRangeException("Start index must be smaller than end index");
            }
            if (startIndex < 0 || endIndex >= this.tableCells.Count)
            {
                throw new ArgumentOutOfRangeException("Invalid start index and end index");
            }
            XWPFTableCell startCell = this.GetCell(startIndex);

            //remove merged cells
            for (int i = endIndex; i > startIndex; i--)
            {
                this.RemoveCell(i);
            }

            if (!startCell.GetCTTc().IsSetTcPr())
            {
                startCell.GetCTTc().AddNewTcPr();
            }
            CT_TcPr tcPr = startCell.GetCTTc().tcPr;

            if (tcPr.gridSpan == null)
            {
                tcPr.AddNewGridspan();
            }
            CT_DecimalNumber gridspan = tcPr.gridSpan;

            gridspan.val = (endIndex - startIndex + 1).ToString();
        }
예제 #5
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);
        }
예제 #6
0
        public XWPFTableCell AddNewTableCell()
        {
            XWPFTableCell xwpfTableCell = new XWPFTableCell(this.ctRow.AddNewTc(), this, this.table.Body);

            this.tableCells.Add(xwpfTableCell);
            return(xwpfTableCell);
        }
예제 #7
0
        /**
         * Adds a new TableCell at the end of this tableRow
         */
        public XWPFTableCell AddNewTableCell()
        {
            CT_Tc         cell      = ctRow.AddNewTc();
            XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.Body);

            tableCells.Add(tableCell);
            return(tableCell);
        }
예제 #8
0
 public static string GetCellText(XWPFTableCell cel)
 {
     StringBuilder sb = new StringBuilder();
     IList<XWPFParagraph> parasList = cel.Paragraphs;
     foreach (XWPFParagraph para in parasList)
     {
         sb.Append(para.ParagraphText);
     }
     return sb.ToString();
 }
예제 #9
0
 public XWPFTable(CT_Tbl table, IBody part, int row, int col)
     : this(table, part)
 {
     for (int i = 0; i < row; i++)
     {
         XWPFTableRow tabRow = (GetRow(i) == null) ? CreateRow() : GetRow(i);
         for (int k = 0; k < col; k++)
         {
             XWPFTableCell tabCell = (tabRow.GetCell(k) == null) ? tabRow
                                     .CreateCell() : null;
         }
     }
 }
예제 #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
 /**
  * create a new XWPFTableCell and add it to the tableCell-list of this tableRow
  * @return the newly Created XWPFTableCell
  */
 public XWPFTableCell CreateCell()
 {
     XWPFTableCell tableCell = new XWPFTableCell(ctRow.AddNewTc(), this, table.Body);
     tableCells.Add(tableCell);
     return tableCell;
 }