/// 复制模板行 /// <param name="templateStartRowIndex"></param> /// <param name="templateEndRowIndex"></param> public void CopyRows(int templateStartRowIndex, int templateEndRowIndex) { var span = templateEndRowIndex - templateStartRowIndex + 1; var insertStartRowIndex = GetCurrentRowIndex(templateStartRowIndex + span); if (insertStartRowIndex < Sheet.LastRowNum) { Sheet.ShiftRows(insertStartRowIndex, Sheet.LastRowNum, span, true, false); } for (int i = templateStartRowIndex; i <= templateEndRowIndex; i++) { var row = Sheet.GetRow(GetCurrentRowIndex(i)); var newRow = Sheet.CopyRow(GetCurrentRowIndex(i), GetCurrentRowIndex(i + span)); newRow.Height = row.Height; newRow.ZeroHeight = row.ZeroHeight; } //获取模板行内的合并区域 var regionInfoList = Sheet.GetAllMergedRegionInfos(GetCurrentRowIndex(templateStartRowIndex), GetCurrentRowIndex(templateEndRowIndex), null, null); //复制合并区域 foreach (var regionInfo in regionInfoList) { regionInfo.FirstRow += span; regionInfo.LastRow += span; Sheet.AddMergedRegion(regionInfo); } //获取模板行内的图片 var picInfoList = Sheet.GetAllPictureInfos(GetCurrentRowIndex(templateStartRowIndex), GetCurrentRowIndex(templateEndRowIndex), null, null); //复制图片 foreach (var picInfo in picInfoList) { picInfo.MaxRow += span; picInfo.MinRow += span; Sheet.AddPicture(picInfo); } _increaseRowsCount += span; }