Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Commented Unassigned: Merged cells detection: two distinct merged cells seen as one [15341]

$
0
0
I've recently noticed that when having two merged cells next to one another, the ExcelRange that matches both cells is seen as merged.

For instance, using this code:
```
var file = new FileInfo("yourFile.xlsx");
using (var ep = new ExcelPackage(file))
{
var ws = ep.Workbook.Worksheets[1];
ws.Cells[25, 8, 25, 13].Merge = true;
ws.Cells[25, 14, 25, 16].Merge = true;

var isResultingRangeMerged = ws.Cells[25, 8, 25, 16].Merge;

ep.Save();
}
```

... you will notice that isResultingRangeMerged returns true.

After taking a look at ExcelRangeBase.cs, it seems that when a range contains only merged cells, the whole range is considered merged, even when it actually contains several distinct cells.

Hence my question: is this an expected behaviour?
Comments: Just in case the answer to my question is negative, here is a fix for the Merge property in ExcelRangeBase.cs: ``` get { IsRangeValid("merging"); var mergedCellIds = new List<int>(); for (int col = _fromCol; col <= _toCol; col++) { for (int row = _fromRow; row <= _toRow; row++) { if(_worksheet.MergedCells[row, col]==null) { return false; } var currentMergedCellId = _worksheet.GetMergeCellId(row, col); if (!mergedCellIds.Contains(currentMergedCellId)) mergedCellIds.Add(currentMergedCellId); if (mergedCellIds.Count > 1) return false; //if (!_worksheet._flags.GetFlagValue(row, col, CellFlags.Merged)) //{ // return false; //} } } return true; } ``` I have no access to the Hg repo right now, but if a more formal pull request is preferred, please feel free to let me know. Thanks in advance for your feedback.

Viewing all articles
Browse latest Browse all 2262

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>