Пример #1
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();
        }