We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Cells Range.Copy not copying anything to destination range

I’m currently using Aspose.Cells v8.4.1.0 for .NET, programming using C# targeting .NET 4.0.


I’m having an issue where if I try to copy range data using Range.Copy() nothing actually gets copied. Range.CopyData and Range.CopyFormat does seem to work though so I can get around the issue, I just wanted to report the bug.

The use case I am working with is that we have a template where there are two rows with even row and odd row formatting (typically only the background color is different). I create a range reference for the entire odd row and entire even row. Then I try to paste the styles to a bulk range of rows that were inserted between the odd template row and even template row.

Below code works as expected:
{code}
//NOTE: currentRow has already been defaulted to evenTemplateRow in the function that read in the tag locations
m_currentWorksheet.Cells.InsertRows(m_mainTable.evenTemplateRow, numRows, true);
//update even row index (was moved when we inserted rows)
m_mainTable.evenTemplateRow += numRows;
//update even row style range reference
m_mainTable.evenStyleRange = m_currentWorksheet.Cells.CreateRange(m_mainTable.evenTemplateRow, 1, false);
//copy the odd row format to every row that was just inserted, this will cut the number of row format copies in half
//because we will now only need to copy the even rows and we can skip copying formulas
Range r = m_currentWorksheet.Cells.CreateRange(m_mainTable.currentRow, numRows, false);
r.CopyData(m_mainTable.oddStyleRange);//apply the odd template row format to EVERY cell (this will save time when we do individual rows because even rows then only need copy of format)
{code}

However, if I switch Range.CopyData to Range.Copy, with or without PasteOptions, nothing gets copied to the newly inserted rows.
{code}
r.Copy(m_mainTable.oddStyleRange, new PasteOptions() { OnlyVisibleCells = false, SkipBlanks = false, Transpose = false, PasteType = PasteType.All });
{code}

The only thing I can think of is that Range.Copy() is failing because the range size is not incidental, whereas Range.CopyData() and Range.CopyStyle() is copying the 1 row template format to all rows in the copy-to range (which is the expected behavior for Excel paste operations). I tried using Range.Copy without PasteOptions, and with all of the PasteOptions.PasteType styles, but nothing worked.

If you need additional information about this issue, please let me know.

Hi,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue by executing the following sample code with the latest version: Aspose.Cells for .NET 8.5.2. Range.CopyData is working fine but Range.Copy is not working.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43836 - Range.CopyData works but Range.Copy is not working

I have also attached the source excel file used in this code and the output excel file generated by it for a reference.

C#

Workbook workbook = new Workbook(“source.xlsx”);

Worksheet worksheet = workbook.Worksheets[0];

Range srcRange = worksheet.Cells.CreateRange(2, 1, false);

Range dstRange = worksheet.Cells.CreateRange(3, 1, false);

//copy data works fine

//dstRange.CopyData(srcRange);

//but copy does not work

dstRange.Copy(dstRange);

workbook.Save(“output.xlsx”);

Hi Ahsun,


This is to inform you that we have fixed the problem logged earlier as CELLSNET-43836. We will shortly provide the fix here with next maintenance release of Aspose.Cells for .NET after incorporating other enhancements and assuring quality of the build. As soon as the fix is available for your testing, you will be notified here in reference to the aforesaid ticket.

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.5.2.1 and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-43836) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,


I’m afraid that the copy functions does not work in 8.6.1. It worked as mentioned in 8.6.0. Please help. Thanks

Hi Volker,


The Range.Copy operation is working fine while using the latest build of Aspose.Cells for .NET 8.6.1.2. You can find my test code at the bottom of this post. Please give the latest version a try on your side. In case the problem persists, please provide us an executable sample application along with its referenced libraries and input/output documents.

C#

Workbook book = new Workbook();
book.Worksheets[0].Cells[“A1”].PutValue(“A1”);
book.Worksheets[0].Cells[“B1”].PutValue(“B1”);
book.Worksheets[0].Cells[“C1”].PutValue(“C1”);
Range source = book.Worksheets[0].Cells.CreateRange(“A1:C1”);
Range destination = book.Worksheets[0].Cells.CreateRange(“A2:C2”);
destination.Copy(source);
book.Save(“c:/temp/output.xlsx”, SaveFormat.Xlsx);