예제 #1
0
        /// <summary>
        /// 移除行
        /// </summary>
        /// <param name="sheet">NPOI工作表</param>
        /// <param name="startRowIndex">起始行索引</param>
        /// <param name="endRowIndex">结束行索引</param>
        public static int RemoveRows(this NPOI.SS.UserModel.ISheet sheet, int startRowIndex, int endRowIndex)
        {
            var span = endRowIndex - startRowIndex + 1;

            sheet.RemoveMergedRegions(startRowIndex, endRowIndex, null, null);
            sheet.RemovePictures(startRowIndex, endRowIndex, null, null);
            for (var i = endRowIndex; i >= startRowIndex; i--)
            {
                var row = sheet.GetRow(i);
                sheet.RemoveRow(row);
            }
            if (endRowIndex + 1 <= sheet.LastRowNum)
            {
                sheet.ShiftRows(endRowIndex + 1, sheet.LastRowNum, -span, true, false);
                sheet.MovePictures(endRowIndex + 1, null, null, null, moveRowCount: -span);
            }
            return(span);
        }