Exemplo n.º 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().Value;
            Assert.AreEqual(XWPFTableCell.XWPFVertAlign.BOTH, al);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 合并行、垂直合并列单元格
        /// </summary>
        /// <param name="table"></param>
        /// <param name="fromRow"></param>
        /// <param name="toRow"></param>
        /// <param name="colIndex"></param>
        public void MYMergeRows(XWPFTable table, int fromRow, int toRow, int colIndex)
        {
            for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++)
            {
                XWPFTableCell rowcell = table.GetRow(rowIndex).GetCell(colIndex);
                rowcell.SetVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                CT_Tc   cttc   = rowcell.GetCTTc();
                CT_TcPr ctTcPr = cttc.tcPr;
                if (ctTcPr == null)
                {
                    ctTcPr = cttc.AddNewTcPr();
                }

                if (rowIndex == fromRow)
                {
                    // The first merged cell is set with RESTART merge value
                    ctTcPr.AddNewVMerge().val = ST_Merge.restart;
                }
                else
                {
                    // Cells which join (merge) the first one, are set with CONTINUE
                    ctTcPr.AddNewVMerge().val = ST_Merge.@continue; //继续合并行
                }
                ctTcPr.AddNewVAlign().val = ST_VerticalJc.center;   //垂直
            }
        }
Exemplo n.º 3
0
        public static XWPFTableCell GetCell(XWPFTableRow row, int line, XWPFTableRow modelRow)
        {
            XWPFTableCell cell = row.GetCell(line);

            if (cell == null)
            {
                cell = row.CreateCell();
                if (modelRow != null)
                {
                    var modelcell = modelRow.GetCell(line);
                    cell.SetVerticalAlignment(modelcell.GetVerticalAlignment());
                    cell.SetColor(modelcell.GetColor());
                }
            }
            return(cell);
        }