//TODO: Optionally provide overload with bool parameter to decide whether to throw //exception instead of losing values. /// <summary> /// Adds a MergeArea to this Worksheet. The mergeArea is verified not to /// overlap with any previously defined area. NOTE Values and formatting /// in all cells other than the first in mergeArea (scanning left to right, /// top to bottom) will be lost. /// </summary> /// <param name="mergeArea">The MergeArea to add to this Worksheet.</param> public void AddMergeArea(MergeArea mergeArea) { foreach (MergeArea existingArea in _mergeAreas) { bool colsOverlap = false; bool rowsOverlap = false; //if they overlap, either mergeArea will surround existingArea, if (mergeArea.ColMin < existingArea.ColMin && existingArea.ColMax < mergeArea.ColMax) { colsOverlap = true; } //or existingArea will contain >= 1 of mergeArea's Min and Max indices else if ((existingArea.ColMin <= mergeArea.ColMin && existingArea.ColMax >= mergeArea.ColMin) || (existingArea.ColMin <= mergeArea.ColMax && existingArea.ColMax >= mergeArea.ColMax)) { colsOverlap = true; } if (mergeArea.RowMin < existingArea.RowMin && existingArea.RowMax < mergeArea.RowMax) { rowsOverlap = true; } else if ((existingArea.RowMin <= mergeArea.RowMin && existingArea.RowMax >= mergeArea.RowMin) || (existingArea.RowMin <= mergeArea.RowMax && existingArea.RowMax >= mergeArea.RowMax)) { rowsOverlap = true; } if (colsOverlap && rowsOverlap) { throw new ArgumentException("overlaps with existing MergeArea", "mergeArea"); } } //TODO: Add ref to this mergeArea to all rows in its range, and add checking on Cell //addition methods to validate they are not being added within the mergedarea, other //than as the top-left cell. _mergeAreas.Add(mergeArea); }
/// <summary> /// Merges cells within the defined range of Rows and Columns. The ranges are /// verified not to overlap with any previously defined Merge areas. NOTE /// Values and formatting in all cells other than the first in the range /// (scanning left to right, top to bottom) will be lost. /// </summary> /// <param name="rowMin">The first index in the range of Rows to merge.</param> /// <param name="rowMax">The last index in the range of Rows to merge.</param> /// <param name="colMin">The first index in the range of Columns to merge.</param> /// <param name="colMax">The last index in the range of Columns to merge.</param> public void Merge(int rowMin, int rowMax, int colMin, int colMax) { MergeArea mergeArea = new MergeArea(rowMin, rowMax, colMin, colMax); _worksheet.AddMergeArea(mergeArea); }
private Bytes CellRangeAddress(MergeArea mergeArea) { return(CellRangeAddress(mergeArea.RowMin, mergeArea.RowMax, mergeArea.ColMin, mergeArea.ColMax)); }