将源范围行高度复制到目标范围
Contents
[
Hide
]
有时用户需要将源范围的行高复制到目标范围。Aspose.Cells为此提供了PasteType.RowHeights枚举。当您将PasteOptions.PasteType属性设置为PasteType.RowHeights枚举时,源范围内所有行的高度将被复制到目标范围。
以下示例代码说明了如何使用PasteType.RowHeights枚举将源范围的行高复制到目标范围。一旦您在Microsoft Excel中打开由此代码生成的输出excel文件,您将看到目标范围的行高与源范围的行高完全相同。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |