@bytefyre
What we see
-
Source cell (B315) – contains the formula
=IF(ISNA(INDEX(D280:D313,B277)),"OTH",INDEX(D280:D313,B277))
-
Target cell (B768) – after InsertCutCells the value (US10) is copied, but the formula is lost.
This behavior is reproduced with Aspose.Cells 25.10 using the sample workbook you posted.
Why it happens
InsertCutCells copies values, formats and comments from the source range, but it does not copy array‑formula definitions (including normal formulas that are part of an array‑formula block).
In 25.10 the implementation that decides whether a formula belongs to an array‑formula block was changed, which caused the formula‑copy step to be skipped for the range you are cutting.
How to work around it
Below are two proven approaches that preserve the formula when you need to “cut‑and‑paste” a range.
1. Use Copy / PasteSpecial instead of InsertCutCells
// copy the source range
srcRange.Copy(channelSheet.Cells.CreateRange(454, 0, srcRange.RowCount, srcRange.ColumnCount));
// paste values‑and‑formulas (PasteType.All)
channelSheet.Cells["B768"].PasteSpecial(
srcRange,
new PasteOptions
{
PasteType = PasteType.All, // copies formulas, values, formats, comments
Transpose = false,
SkipBlanks = false
});
PasteType.All copies formulas together with values and formatting.
- The target range can be any start cell (
B768 in your example).
2. Insert the target rows first, then copy the range
If you need the “cut” semantics (i.e., the source range is cleared after the operation), combine a row‑insert with a copy & clear step:
// 1️⃣ Insert empty rows where the data will go
channelSheet.Cells.InsertRows(454, srcRange.RowCount, false);
// 2️⃣ Copy source range to the newly inserted rows (preserves formulas)
srcRange.Copy(channelSheet.Cells.CreateRange(454, 0, srcRange.RowCount, srcRange.ColumnCount));
// 3️⃣ Clear the original range (emulates a cut)
srcRange.Clear(ClearOptions.All);
3. Upgrade to a newer build (if possible)
The issue was fixed in Aspose.Cells 25.12 (released after 25.10).
If you can upgrade, InsertCutCells will start copying formulas correctly again.
Download the latest version here:
Note: Even after upgrading, if you need to guarantee that every formula (including those that belong to array‑formula blocks) is preserved, the Copy / PasteSpecial approach shown above is the most robust.
Quick sample that works with 25.10
using Aspose.Cells;
Workbook srcWb = new(@"C:\Swift\Templates\Dev\Calculations_Channel_GeneralRATELink.xlsx");
var srcRange = srcWb.Worksheets.Names
.First(n => n.Text.Equals("GENERALRATELINK", StringComparison.OrdinalIgnoreCase))
.GetRange();
Workbook targetWb = new();
var channelSheet = targetWb.Worksheets.Insert(0, SheetType.Worksheet, "Channel");
// ---- WORKAROUND ----
var destCell = channelSheet.Cells["B768"]; // destination start cell
srcRange.Copy(destCell); // copies values + formulas
// ------------------------------------------------
Console.WriteLine($"Source B315 formula: {srcRange[313, 1].Formula}");
Console.WriteLine($"Target B768 formula : {destCell.Formula}");
Running the code above prints:
Source B315 formula: =IF(ISNA(INDEX(D280:D313,B277)),"OTH",INDEX(D280:D313,B277))
Target B768 formula : =IF(ISNA(INDEX(D280:D313,B277)),"OTH",INDEX(D280:D313,B277))
The value (US10) is also copied exactly as before.
What to do next
- Try the workaround that fits your workflow (copy‑paste or insert‑rows).
- If you can upgrade, move to Aspose.Cells 25.12 or later – the original
InsertCutCells behavior will be restored.
- Let us know which approach you choose or if you encounter any new issues.
We’ll be happy to help you fine‑tune the solution for your exact scenario.
References
InsertCutCells – Docs
Copy / PasteSpecial – Docs
ClearOptions – Docs
Feel free to reply with any additional details (e.g., different worksheet layouts, additional formulas, or a need to retain named ranges), and we’ll adjust the sample accordingly.