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

Free Support Forum - aspose.com

CopyStyle - Source Range Size


I've searched your help and forums and don't see it written anywhere that for CopyStyle to work properly, the source range must be bigger than, or equal to, the destination range. I'm therefore wondering whether this behaviour is by design or unintentional. For example (in VB):

r = wks.Cells.CreateRange("a1:e1")
r2 = wks.Cells.CreateRange("a2:e6")


Because the source range (r) is only 1 row, the formatting is only copied to the first row of the destination range (r2). The solution is to loop through each row of the destination range but that seems a little clumsy when Excel automation performs the action in one statement. If you could confirm whether this is intentional behaviour that would be appreciated.

Thanks, Glynn.


I think you may try like following, kindly refer to the following sample code:
Sample code:

Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
Range range = cells.CreateRange(“B1:G1”);
Range dRange = cells.CreateRange(“B12:B17”);
PasteOptions options = new PasteOptions();
options.PasteType = PasteType.Values;
options.Transpose = true;
dRange.Copy(range, options);

Hope, this helps a bit.

Thank you.

Thanks Amjad. If the CopyStyle behaviour is intentional as you imply, I will simply loop through the destination rows as suggested in my question. I appreciate your fast response.


Well, yes you may try your workaround to copy the formatting from source to destination range of cells. Also, you may try the following line instead if it works for you:
Sample code:

options.PasteType = PasteType.All;

Thank you.