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

Free Support Forum - aspose.com

Pasting a range to another sheet resizes the columns

Hi,


Pasting a range from one sheet to another causes the column’s width to be resized.
When pasting using Excel this is not the case.

If you use the attached file with the following code:

var workbook = new Workbook(“Imagy.xlsx”);
var ws = workbook.Worksheets[0];
var ws2 = workbook.Worksheets[1];
var fromRange = ws.Cells.CreateRange(0, 0, 5, 5);
var toRange = ws2.Cells.CreateRange(0, 0, 1, 1);
toRange.Copy(fromRange);

workbook.Save(“ImagyOut.xlsx”);

You will see that the ‘A’ column is now smaller and this causes the image to overlap the data in column ‘B’. If you set the picture to size with cells it will be resized to the new column size and look squashed.

Best regards.

Hi John,


Thank you for contacting Aspose support.

Please use the overloaded version of Range.Copy method that accepts a second parameter of type PasteOptions and specify PasteType.Values as demonstrated below. This should retain the column widths of the destination range.

C#

var workbook = new Workbook(“D:/temp/Imagy.xlsx”);
var ws = workbook.Worksheets[0];
var ws2 = workbook.Worksheets[1];
var fromRange = ws.Cells.CreateRange(0, 0, 5, 5);
var toRange = ws2.Cells.CreateRange(0, 0, 1, 1);
toRange.Copy(fromRange, new PasteOptions() { PasteType = PasteType.Values});
workbook.Save(“ImagyOut.xlsx”);

Hi,


Thanks for your reply.

Although this does solve the issue, the example I provided above was probably too simplistic.
I naturally also would like any formatting, borders, background colour, font etc. to be copied along as well.
I basically want it to work in the same way as copying from one Excel sheet to another works in Excel.

I have attached another example file. If you manually copy paste with Excel, you will see that everything is copied across except for column widths.
Excel does have an option to ‘keep source column widths’ but this is only an option, not the default.

Unless I am missing something, this seems to be a missing option in the PasteTypes?

Thanks.

Hi John,


Thank you for elaborating your requirement.

It seems to be a feature request, as the current implementation of Aspose.Cells for .NET API does not offer any means to keep the columns widths of the destination range intact while copying everything else from the source range. We have logged your request under the ticket CELLSNET-43309 for feasibility analysis. You have to spare us little time to analyze your request, and consequently bring your requested feature on our road map of Aspose.Cells APIs. In the meanwhile, we will keep you posted with updates in this regard.

Hi,

Thanks for your using Aspose.Cells.

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

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


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