نسخ ارتفاعات الصف من النطاق المصدر إلى النطاق الوجهة
Contents
[
Hide
]
في بعض الأحيان، يحتاج المستخدم إلى نسخ ارتفاعات الصف من نطاق المصدر إلى نطاق الوجهة. توفر Aspose.Cells enum PasteType.RowHeights لهذا الغرض. عندما تقوم بتعيين الخاصية PasteOptions.PasteType بـ PasteType.RowHeights enum، سيتم نسخ ارتفاعات جميع الصفوف داخل نطاق المصدر إلى نطاق الوجهة.
يوضح الكود العيني التالي كيفية استخدام enum PasteType.RowHeights لنسخ ارتفاعات الصف من نطاق المصدر إلى نطاق الوجهة. بمجرد فتح ملف إكسل الناتج الذي تم إنشاؤه بواسطة هذا الكود في Microsoft Excel، سترى أن ارتفاعات صفوف نطاق الوجهة تطابق تمامًا مع ارتفاعات صفوف نطاق المصدر.
This file contains 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); |