示例#1
0
        /// <param name="srcSheet"> the sheet to copy. </param>
        /// <param name="destSheet"> the sheet to create. </param>
        /// <param name="srcRow"> the row to copy. </param>
        /// <param name="destRow"> the row to create. </param>
        /// <param name="styleMap"> - </param>
        private static void CopyRow(ISheet srcSheet, ISheet destSheet, IRow srcRow, IRow destRow,
                                    IDictionary <int?, ICellStyle> styleMap)
        {
            // manage a list of merged zone in order to not insert two times a merged zone
            SortedSet <CellRangeAddressWrapper> mergedRegions = new SortedSet <CellRangeAddressWrapper>();

            destRow.Height = srcRow.Height;
            // reckoning delta rows
            int deltaRows = destRow.RowNum - srcRow.RowNum;
            // pour chaque row
            int j = srcRow.FirstCellNum < 0 ? 0 : srcRow.FirstCellNum;

            for (; j <= srcRow.LastCellNum; j++)
            {
                ICell oldCell = srcRow.GetCell(j);  // ancienne cell
                ICell newCell = destRow.GetCell(j); // new cell
                if (oldCell != null)
                {
                    if (newCell == null)
                    {
                        newCell = destRow.CreateCell(j);
                    }
                    // copy chaque cell
                    CopyCell(oldCell, newCell, styleMap);
                    // copy les informations de fusion entre les cellules
                    CellRangeAddress mergedRegion = GetMergedRegion(srcSheet, srcRow.RowNum, (short)oldCell.ColumnIndex);

                    if (mergedRegion != null)
                    {
                        CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.FirstRow + deltaRows,
                                                                                mergedRegion.LastRow + deltaRows,
                                                                                mergedRegion.FirstColumn,
                                                                                mergedRegion.LastColumn);
                        CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
                        if (IsNewMergedRegion(wrapper, mergedRegions))
                        {
                            mergedRegions.Add(wrapper);
                            destSheet.AddMergedRegion(wrapper.range);
                        }
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Check that the merged region has been created in the destination sheet. </summary>
 /// <param name="newMergedRegion"> the merged region to copy or not in the destination sheet. </param>
 /// <param name="mergedRegions"> the list containing all the merged region. </param>
 /// <returns> true if the merged region is already in the list or not. </returns>
 private static bool IsNewMergedRegion(CellRangeAddressWrapper newMergedRegion,
                                       SortedSet <CellRangeAddressWrapper> mergedRegions)
 {
     return(!mergedRegions.Contains(newMergedRegion));
 }