Moving multi-row range copies the first row

What I have here, is


Range := TXLSCellRange.Create(2, 1, 3, 33);
MyXLSFile.InsertAndCopyRange(Range, 3, 1, 2, TFlxInsertMode.NoneDown,
          TRangeCopyMode.All);


I am intending to move the whole range, 3 rows in total, one row down. I can't insert an empty row on top as that throws off graph data sources.

In theory, the first command should create a range containing 3 lines, 33 columns and the second line insert all this. In practice, only the first line of the source range gets inserted. 3 times. Can anyone tell me my mistake?

Can't find the edit button, I insert the range once, not twice. The 2 was an artifact of trying to find out what's wrong.

Hi,

This is sadly a limitation in InsertAndCopyRange: It copies in place, so the range where you are copying must not intersect with the range where you are copying. If you copy rows 2 and 3 (note that the range in your example is 2 rows, not 3), into row 3, then first row 2 is copied into row 3, then row 3 into row 4, but the row3 copied into row4 is row2, as it was copied into row3 before.

Fixing this would sadly have serious performance implications (since we need to do a temporary copy of the cells to avoid overwriting them), and InsertAndCopyRange is a critical method in FlexCel: It must be as fast as possible.

But I think in your case, if you are trying to move the range, it would make more sense to use MoveRange() instead?

 xls.MoveRange(Range1, 3, 1, TFlxInsertMode.NoneDown, true);

Works fine here, and I think it will do what you want. MoveRange is not as critical as InsertAndCopyRange, and it can afford to temporary copy the data. The other solution would be to 2 two InsertAndCopyRange: Say from A1 to AA1, then from AA1 to A2. This way the ranges being copied won't overlap. But I think in this case MoveRange is just the simplest solution.