Pasting formatting of a range resulted in an empty range pasted in the destination


When I tried to copy/paste the formats of a range, I noticed the destination is empty.

var workbook = new Workbook(@".\test2.xlsx");
var fromRange = workbook.Worksheets[0].Cells.CreateRange(1, 0, 10, 1).EntireRow; // copy rows 1 - 10
var toRange = workbook.Worksheets[1].Cells.CreateRange(1, 0, 1, 1);
toRange.Copy(fromRange, new PasteOptions() { PasteType = PasteType.Formats }); // copy the formats from the range
// I also tried the line below rather than toRange.Copy but results were the same
// toRange.Worksheet.Cells.CopyRows(workbook.Worksheets[0].Cells, fromRange.FirstRow, toRange.FirstRow, fromRange.RowCount, new CopyOptions(), new PasteOptions() { PasteType = PasteType.Formats }); // copy the formats from the range
workbook.Save(@".\out.xlsx"); // worksheet 2 is empty

Supposedly, after executing the copy, the data in the 2nd worksheet should have the same formatting as the first sheet (which is correct if I use Office Excel manually). However, it actually ended up the data in the 2nd worksheet destination was removed completely!

I’ve attached the test files and a screenshot for your reference. Could you please help me take a look?

image.png (29.1 KB) (13.7 KB)


It seems that you are not setting the toRange properly. I have changed following line and the desired output is generated. Please try it and set toRange properly as per your requirement.

var toRange = workbook.Worksheets[1].Cells.CreateRange(1, 0, 10, 10);

In Word, I can put my range to A2 without any additional selection before pasting. Also in Aspose, it works with any other paste options like


so I don’t think it is a requirement to have the destination range to be pre-selected to be the same the source range. (and even in your example code, it is not selecting the same range as the code I used was to copy the entire row)

Could you please take a further look into this.


We need to analyze this issue in detail and have logged it for further investigation as follows:

CELLSNET-47430 - Pasting formatting of a range resulted in an empty range pasted in the destination

If the PasteType is PasteType.Formats, Aspose.Cells only paste styles of the cells to destination and works same as MS Excel.
Please check Cell A2 in worksheet “sheet2”, the font color is red.


Thanks for your feedback. As I mentioned in my initial comments, I tried and compared the behaviour in Excel.

In the test files, the sheet2 already had data before paste, but once the paste format is done, the formatting is applied but the data in sheet2 is removed.

This is different than Excel, where if I paste format there, the formatting is applied and data is not removed.



You are right as I tested your scenario/ case manually in MS Excel using Paste Special option. Anyways, let us evaluate if this behavior of Ms Excel is correct or wrong.

Once we have an update on it, we will let you know.

This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-47430”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

Please try our latest version/fix: Aspose.Cells for .NET v20.6.2:

Aspose.Cells20.6.2 For .Net4.0.Zip (5.4 MB)
Aspose.Cells20.6.2 For .Net2_AuthenticodeSigned.Zip (5.4 MB)

Your issue should be fixed in it.

Let us know your feedback.

The issues you have found earlier (filed as CELLSNET-47430) have been fixed in Aspose.Cells for .NET v20.7. This message was posted using Bugs notification tool by ahsaniqbalsidiqui