إعادة استخدام كائنات النمط
Contents
[
Hide
]
يمكن لإعادة استخدام كائنات النمط توفير الذاكرة وجعل البرنامج أسرع.
لتطبيق بعض التنسيق على مجموعة كبيرة من الخلايا في ورقة العمل:
- إنشاء كائن النمط.
- تحديد السمات.
- تطبيق النمط على الخلايا في النطاق.
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(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access cells | |
Cell cell1 = worksheet.Cells["A1"]; | |
Cell cell2 = worksheet.Cells["B1"]; | |
// Set the styles of both cells to Times New Roman | |
Style styleObject = workbook.CreateStyle(); | |
styleObject.Font.Color = System.Drawing.Color.Red; | |
styleObject.Font.Name = "Times New Roman"; | |
cell1.SetStyle(styleObject); | |
cell2.SetStyle(styleObject); | |
// Put the values inside the cell | |
cell1.PutValue("Hello World!"); | |
cell2.PutValue("Hello World!!"); | |
// Save to Pdf without setting PdfSaveOptions.IsFontSubstitutionCharGranularity | |
workbook.Save(dataDir + "SampleOutput_out.xlsx"); |
نظرًا لأن النهج Cell.GetStyle/Cell.SetStyle يستخدم أقل من الذاكرة بكثير، وهو كفء، تمت إزالة خاصية Cell.Style القديمة التي كانت تستهلك الكثير من الذاكرة غير الضرورية مع إصدار Aspose.Cells 7.1.0.