コード例 #1
0
        /// <summary>
        /// Deletes one or more rows at the specified position in the table.
        /// </summary>
        /// <param name="position">The position in the table where the row will be deleted. 0 will delete the first row. </param>
        /// <param name="rows">Number of rows to delete.</param>
        /// <returns></returns>
        public ExcelRangeBase DeleteRow(int position, int rows = 1)
        {
            if (position < 0)
            {
                throw new ArgumentException("position", "position can't be negative");
            }
            if (rows < 0)
            {
                throw new ArgumentException("position", "rows can't be negative");
            }
            if (_address._fromRow + position + rows > _address._toRow)
            {
                throw new InvalidOperationException("Delete will exceed the number of rows in the table");
            }
            var subtract = ShowTotal ? 2 : 1;

            if (position == 0 && rows + subtract >= _address.Rows)
            {
                throw new InvalidOperationException("Can't delete all table rows. A table must have at least one row.");
            }
            position++; //Header row should not be deleted.
            var address = ExcelCellBase.GetAddress(_address._fromRow + position, _address._fromCol, _address._fromRow + position + rows - 1, _address._toCol);
            var range   = new ExcelRangeBase(WorkSheet, address);

            range.Delete(eShiftTypeDelete.Up);
            return(range);
        }