Dears,
It is no longer possible use Merge property to unmerge a range:
In version 4.0.1 (In ExcelRangeBase.cs):
> ExcelRange.Merge = false
has same effect as
> ExcelRange.Merge = true
Should there be other way how to unmerge? Or it is planned to be added? Or it is a bug?
Thank you
Meanwhile I have updated the setter of Merge property in my project to code below:
```
set
{
IsRangeValid("merging");
//SetMerge(value, FirstAddress);
if (!value)
{
if (_worksheet.MergedCells.Contains(FirstAddress))
{
_worksheet.MergedCells.Remove(FirstAddress);
}
else
{
throw (new ArgumentException("Range is not merged"));
}
if (Addresses != null)
{
foreach (var address in Addresses)
{
if (_worksheet.MergedCells.Contains(address.Address))
{
_worksheet.MergedCells.Remove(address.Address);
}
else
{
throw (new ArgumentException("Range is not merged"));
}
}
}
}
else
{
_worksheet.MergedCells.Add(new ExcelAddressBase(FirstAddress), true);
if (Addresses != null)
{
foreach (var address in Addresses)
{
_worksheet.MergedCells.Add(address, true);
//SetMerge(value, address._address);
}
}
}
}
```
Comments: I think that you need clear the cells, like this ``` set { IsRangeValid("merging"); //SetMerge(value, FirstAddress); if (!value) { if (_worksheet.MergedCells.Contains(FirstAddress)) { _worksheet.MergedCells.Remove(FirstAddress); ExcelAddress a = new ExcelAddress(FirstAddress); _worksheet.MergedCells._cells.Clear(a._fromRow, a._fromCol, a._toRow, a._toCol); } else { throw (new ArgumentException("Range is not merged")); } if (Addresses != null) { foreach (var address in Addresses) { if (_worksheet.MergedCells.Contains(address.Address)) { _worksheet.MergedCells.Remove(address.Address); ExcelAddress a = new ExcelAddress(address.Address); _worksheet.MergedCells._cells.Clear(a._fromRow, a._fromCol, a._toRow, a._toCol); } else { throw (new ArgumentException("Range is not merged")); } } } } else { _worksheet.MergedCells.Add(new ExcelAddressBase(FirstAddress), true); if (Addresses != null) { foreach (var address in Addresses) { _worksheet.MergedCells.Add(address, true); //SetMerge(value, address._address); } } } } ```
It is no longer possible use Merge property to unmerge a range:
In version 4.0.1 (In ExcelRangeBase.cs):
> ExcelRange.Merge = false
has same effect as
> ExcelRange.Merge = true
Should there be other way how to unmerge? Or it is planned to be added? Or it is a bug?
Thank you
Meanwhile I have updated the setter of Merge property in my project to code below:
```
set
{
IsRangeValid("merging");
//SetMerge(value, FirstAddress);
if (!value)
{
if (_worksheet.MergedCells.Contains(FirstAddress))
{
_worksheet.MergedCells.Remove(FirstAddress);
}
else
{
throw (new ArgumentException("Range is not merged"));
}
if (Addresses != null)
{
foreach (var address in Addresses)
{
if (_worksheet.MergedCells.Contains(address.Address))
{
_worksheet.MergedCells.Remove(address.Address);
}
else
{
throw (new ArgumentException("Range is not merged"));
}
}
}
}
else
{
_worksheet.MergedCells.Add(new ExcelAddressBase(FirstAddress), true);
if (Addresses != null)
{
foreach (var address in Addresses)
{
_worksheet.MergedCells.Add(address, true);
//SetMerge(value, address._address);
}
}
}
}
```
Comments: I think that you need clear the cells, like this ``` set { IsRangeValid("merging"); //SetMerge(value, FirstAddress); if (!value) { if (_worksheet.MergedCells.Contains(FirstAddress)) { _worksheet.MergedCells.Remove(FirstAddress); ExcelAddress a = new ExcelAddress(FirstAddress); _worksheet.MergedCells._cells.Clear(a._fromRow, a._fromCol, a._toRow, a._toCol); } else { throw (new ArgumentException("Range is not merged")); } if (Addresses != null) { foreach (var address in Addresses) { if (_worksheet.MergedCells.Contains(address.Address)) { _worksheet.MergedCells.Remove(address.Address); ExcelAddress a = new ExcelAddress(address.Address); _worksheet.MergedCells._cells.Clear(a._fromRow, a._fromCol, a._toRow, a._toCol); } else { throw (new ArgumentException("Range is not merged")); } } } } else { _worksheet.MergedCells.Add(new ExcelAddressBase(FirstAddress), true); if (Addresses != null) { foreach (var address in Addresses) { _worksheet.MergedCells.Add(address, true); //SetMerge(value, address._address); } } } } ```