Free Support Forum -

Alternative to Cut/Paste for Ranges


I have a program that currently uses Interop’s cut/paste functionality to change the ordering of entire columns within a worksheet while updating the references (defined names, conditional formatting, formulas, etc.). Is there a way that I’m missing to do this? I’ve tried the Range.MoveTo() method but it’s caused tons of issues.



You may please give a try to the sample code below which performs following steps:

  1. Open workbook

  2. Get first worksheet

  3. Insert column at D

  4. Set PasteType to Default so that it mimics the “All” behavior of Excel

  5. Copy data from column B to D using above mentioned paste options

  6. Delete column B

  7. Save workbook

    Workbook wb = new Workbook(@“Book1.xlsx”);
    Worksheet ws = wb.Worksheets[0];

    //Insert column at D
    wb.Worksheets[0].Cells.InsertColumns(3, 1, true);

    // Set PasteOptions
    PasteOptions pasteOptions = new PasteOptions();
    pasteOptions.PasteType = PasteType.Default;
    pasteOptions.OnlyVisibleCells = true;

    //Copy Data from column B to D
    ws.Cells.CopyColumns(ws.Cells, 1, 3, 1, pasteOptions);

    //Delete column B
    ws.Cells.DeleteColumns(1, 1, true);
    wb.Save(@“Book2.xlsx”); (7.1 KB) (7.4 KB) (14.3 KB)


This carries over the conditional formatting, but if you placed a defined name on the range that you’re copying, it won’t get moved over properly.



Please share your sample file and runnable code snippet with us for our testing. We will reproduce the problem and provide our feedback after analysis.



Here’s what I’m using to test your method. As you will see, the defined name “NamedRange” will be #REF in book2.

            Workbook wb = new Workbook();
        Worksheet ws = wb.Worksheets[0];

        ws.Cells[0, 2].Value = 1;
        ws.Cells[1, 2].Value = 2;
        ws.Cells[2, 2].Value = 3;

        ws.Cells.CreateRange(0, 2, 3, 1).Name = "NamedRange";


        PasteOptions pasteOptions = new PasteOptions();
        pasteOptions.PasteType = PasteType.Default;
        pasteOptions.OnlyVisibleCells = true;

        ws.Cells.CopyColumns(ws.Cells, 2, 1, 1, pasteOptions);
        ws.Cells.DeleteColumns(2, 1, true);




We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46643 - Named ranges are not copied while copying a column



We evaluated your issue further. We found MS Excel does not copy the named range when copying columns, please check it in MS Excel manually. Aspose.Cells works as the same way as MS Excel does, so we have no plan to fix your issue.

Thanks for your understanding!


Thank you @Amjad_Sahi. While I understand that the Aspose copy method follows the MS Excel method, The reasoning for posting in this topic was to see if there is a way to mimic how Excel cuts (different than copy). Is there any plan to include this in Aspose?



I am afraid, we might not support or fix it. The reason is it will violate Ms Excel standards and it might affect some other users who mimic MS Excel behavior when copying rows and columns in Excel sheets.



I can understand why you would not want to change the current copy/paste methodology. However, cut and copy are two different operations in MS Excel.

See these:



I have logged your comments with the ticket for our reference and will look into it in detail. I will write back here once any feedback is ready to share.


Thank you! Looking forward to your feedback while we are in the trial process of your product.



You are welcome.


@ahsaniqbalsidiqui any update on this?



This new feature request is still pending and not planned yet, therefore no ETA can be provided. We will write back here once any feedback is ready to share.