إعادة استخدام كائنات النمط
Contents
[
Hide
]
يمكن أن تؤدي إعادة استخدام كائنات النمط إلى توفير الذاكرة وجعل تنفيذ البرنامج أسرع.
لتطبيق بعض التنسيقات على نطاق كبير من الخلايا في ورقة عمل:
- قم بإنشاء كائن نمط.
- حدد السمات.
- قم بتطبيق النمط على الخلايا الموجودة في النطاق.
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ReuseStyleObjects.class); | |
// Create an instance of Workbook & load an existing spreadsheet | |
Workbook workbook = new Workbook(dataDir + "Book1.xls"); | |
// Retrieve the Cell Collection of the first Worksheet | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// Create an instance of Style and add it to the pool of styles | |
Style styleObject = workbook.createStyle(); | |
// Retrieve the Font object of newly created style | |
Font font = styleObject.getFont(); | |
// Set the font color to Red | |
font.setColor(Color.getRed()); | |
// Set the newly created style on two different cells | |
cells.get("A1").setStyle(styleObject); | |
cells.get("A2").setStyle(styleObject); |
يمكن أيضًا إنجاز نفس العملية التي تمت مناقشتها أعلاه على النحو التالي.
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
cells.get("A1").getStyle().getFont().setColor(Color.getRed()); | |
cells.get("A2").getStyle().getFont().setColor(Color.getRed()); |
بسبب الCell.getStyle وCell.setStyle الأساليب التي تستخدم ذاكرة أقل بكثير وهي فعالة ، أقدمCell.getStyle () تمت إزالة الخاصية التي استهلكت الكثير من الذاكرة غير الضرورية مع إصدارAspose.Cells 7.1.0.