إعادة استخدام كائنات النمط
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
from aspose.cells import Workbook | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook object | |
workbook = Workbook() | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access cells | |
cell1 = worksheet.cells.get("A1") | |
cell2 = worksheet.cells.get("B1") | |
# Set the styles of both cells to Times New Roman | |
styleObject = workbook.create_style() | |
styleObject.font.color = Color.red | |
styleObject.font.name = "Times New Roman" | |
cell1.set_style(styleObject) | |
cell2.set_style(styleObject) | |
# Put the values inside the cell | |
cell1.put_value("Hello World!") | |
cell2.put_value("Hello World!!") | |
# Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
workbook.save(dataDir + "SampleOutput_out.xlsx") |
نظرًا لأن النهج Cell.get_style/Cell.set_style يستخدم أقل من الذاكرة بكثير، وهو كفء، تمت إزالة خاصية Cell.Style القديمة التي كانت تستهلك الكثير من الذاكرة غير الضرورية مع إصدار Aspose.Cells 7.1.0.