الحصول على كائن الخلية حسب اسم العرض المتجانس لحقل PivotField من جدول الدوران
Contents
[
Hide
]
تقدم Aspose.Cells لـ Python via .NET PivotTable.get_cell_by_display_name(display_name) الذي يمكنك استخدامه للوصول إلى كائن الخلية بواسطة اسم العرض لحقل pivot. يعتبر هذا الأسلوب مفيدًا عندما تريد تحديد أو تنسيق رأس حقل الجدول المحوري الخاص بك. تشرح هذه المقالة كيفية استرداد كائن الخلية بواسطة اسم العرض لحقل البيانات ثم تطبيق التنسيق عليه.
كيفية الحصول على كائن الخلية بواسطة اسم العرض لحقل PivotField في جدول البيانات المحوري
يقوم الكود التالي بالوصول إلى أول جدول مفصلي في ورقة العمل ثم الحصول على الخلية بواسطة اسم العرض لحقل البيانات الثاني في الجدول المفصلي. يغير بعد ذلك لون التعبئة ولون الخط للخلية إلى اللون الأزرق الفاتح والأسود على التوالي. تُظهر اللقطات الشاشية أدناه كيفية ظهور الجدول المفصلي قبل وبعد تنفيذ الكود.
جدول مفصلي - قبل |
---|
![]() |
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
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 from source excel file | |
workbook = Workbook(dataDir + "source.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access first pivot table inside the worksheet | |
pivotTable = worksheet.pivot_tables[0] | |
# Access cell by display name of 2nd data field of the pivot table | |
cell = pivotTable.get_cell_by_display_name(pivotTable.data_fields[0].display_name) | |
# Access cell style and set its fill color and font color | |
style = cell.get_style() | |
style.foreground_color = Color.light_blue | |
style.font.color = Color.black | |
# Set the style of the cell | |
pivotTable.format(cell.row, cell.column, style) | |
# Save workbook | |
workbook.save(dataDir + "output_out.xlsx") |
جدول مفصلي - بعد |
---|
![]() |