Open craigbrown opened 3 years ago
No, the range is no updated when inserting or deleting in a range. As this is the current behavior we can't really change it, but we will look at returning the inserted/deleted range from the methods instead, as they are of declared void as of today. For example:
[TestMethod]
public void CheckRangeAddressAfterInsertingCells()
{
using (var pck = new ExcelPackage())
{
// Create a worksheet
var wks = pck.Workbook.Worksheets.Add("Sheet1");
// Get a range
var rng = wks.Cells["B3:B5"];
Assert.AreEqual("B3:B5", rng.LocalAddress);
// Insert cells to the left
var insertedRng = rng.Insert(eShiftTypeInsert.Right);
// Check the range has shifted right
Assert.AreEqual("C3:C5", insertedRng.LocalAddress);
}
}
OK - that wouldn't technically be the inserted range that you're returning though. The rng
object currently automatically becomes the inserted range, and you'd be returning the range that rng
was previously pointing to.
It would make more sense for the inserted range to be returned and rng
to continue pointing to the same cells which have been shifted right. But if that's too much of a breaking change this is an ok compromise, although some might find it confusing.
Yes, insertedRng will be set to the range updated after the insert or delete operation. rng will still point to B3:B5. Otherwise we will have a breaking change.
Same effect applies when defining a ExcelNamedRange and then inserting a full row before that using sheet.InsertRow()
.
The Address Attribute of the range gets updated to the original Row +1. Start and End Attributes of the Range are not.
This is a breaking change compared to v5.6.4 which I used previously.
Is there any ETA on this?
If I have a range that refers to
B3
, and then I insert cells, I expect that the range is updated to eitherC3
(if shifting right) orB4
(if shifting down). But the range object just stays pointing atB3
.Is that expected behaviour? It's different to how it works in VBA/Interop so just wanted to check whether this was intentional.