Copy Row Heights of Source Range to Destination Range

Contents
[ ]

The following sample code explains how to use PasteType.RowHeights enum to copy row heights of source range into destination range. Once you will open the output excel file generated by this code in Microsoft Excel, you will see that destination range row heights are exactly the same as source range row heights.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook object
Workbook workbook = new Workbook();
// Source worksheet
Worksheet srcSheet = workbook.Worksheets[0];
// Add destination worksheet
Worksheet dstSheet = workbook.Worksheets.Add("Destination Sheet");
// Set the row height of the 4th row. This row height will be copied to destination range
srcSheet.Cells.SetRowHeight(3, 50);
// Create source range to be copied
Range srcRange = srcSheet.Cells.CreateRange("A1:D10");
// Create destination range in destination worksheet
Range dstRange = dstSheet.Cells.CreateRange("A1:D10");
// PasteOptions, we want to copy row heights of source range to destination range
PasteOptions opts = new PasteOptions();
opts.PasteType = PasteType.RowHeights;
// Copy source range to destination range with paste options
dstRange.Copy(srcRange, opts);
// Write informative message in cell D4 of destination worksheet
dstSheet.Cells["D4"].PutValue("Row heights of source range copied to destination range");
// Save the workbook in xlsx format
workbook.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx);