انسخ ارتفاعات الصفوف من نطاق المصدر إلى نطاق الوجهة
Contents
[
Hide
]
في وقت ما يحتاج المستخدم إلى نسخ ارتفاعات الصفوف من نطاق المصدر إلى نطاق الوجهة. يوفر Aspose.Cellsلصق النوع. ROW_HEIGHTS تعداد لهذا الغرض. عندما تقوم بتعيينPasteOptions.setPasteType () الملكية معلصق النوع. ROW_HEIGHTS تعداد ثم سيتم نسخ ارتفاعات جميع الصفوف داخل نطاق المصدر إلى النطاق الوجهة.
انسخ ارتفاعات الصفوف من نطاق المصدر إلى نطاق الوجهة
يوضح نموذج التعليمات البرمجية التالي كيفية الاستخداملصق النوع. ROW_HEIGHTSتعداد لنسخ ارتفاعات الصفوف من نطاق المصدر إلى نطاق الوجهة. بمجرد فتح ملف Excel الناتج الذي تم إنشاؤه بواسطة هذا الرمز في 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CopyRowHeights.class); | |
// Create workbook object | |
Workbook workbook = new Workbook(); | |
// Source worksheet | |
Worksheet srcSheet = workbook.getWorksheets().get(0); | |
// Add destination worksheet | |
Worksheet dstSheet = workbook.getWorksheets().add("Destination Sheet"); | |
// Set the row height of the 4th row | |
// This row height will be copied to destination range | |
srcSheet.getCells().setRowHeight(3, 50); | |
// Create source range to be copied | |
Range srcRange = srcSheet.getCells().createRange("A1:D10"); | |
// Create destination range in destination worksheet | |
Range dstRange = dstSheet.getCells().createRange("A1:D10"); | |
// PasteOptions, we want to copy row heights of source range to destination range | |
PasteOptions opts = new PasteOptions(); | |
opts.setPasteType(PasteType.ROW_HEIGHTS); | |
// Copy source range to destination range with paste options | |
dstRange.copy(srcRange, opts); | |
// Write informative message in cell D4 of destination worksheet | |
dstSheet.getCells().get("D4").putValue("Row heights of source range copied to destination range"); | |
// Save the workbook in xlsx format | |
workbook.save(dataDir + "output.xlsx", SaveFormat.XLSX); |