/// <summary> /// 根据偏移量复制范围 /// </summary> /// <param name="sheet"></param> /// <param name="sourceRange"></param> /// <param name="offset"></param> public static void CopyRangeByOffset(this ISheet sheet, CellRange sourceRange, CellOffset offset) { var regionInfoList = sheet.GetMergedRegionInfos(sourceRange); sheet.RemoveMergedRegions(sourceRange); for (var rowIndex = sourceRange.EndLocation.RowIndex; rowIndex >= sourceRange.StartLocation.RowIndex; rowIndex--) { var targetRowIndex = rowIndex + offset.OffsetY; var sourceRow = sheet.GetRow(rowIndex); for (var columnIndex = sourceRange.EndLocation.ColumnIndex; columnIndex >= sourceRange.StartLocation.ColumnIndex; columnIndex--) { var targetColumnIndex = columnIndex + offset.OffsetX; var sourceCell = sourceRow?.GetCell(columnIndex); sheet.CopyCell(sourceCell, new CellLocation(targetColumnIndex, targetRowIndex)); } } foreach (MergedRegionInfo regionInfo in regionInfoList) { regionInfo.Range += offset; sheet.AddMergedRegion(regionInfo); } }