تنسيق الجدول المحوري Cells
Contents
[
Hide
]
في بعض الأحيان ، تريد تنسيق خلايا الجدول المحوري. على سبيل المثال ، تريد تطبيق لون الخلفية على خلايا الجدول المحوري. يوفر Aspose.Cells طريقتينPivotTable.formatAll () وPivotTable.format () ، والتي يمكنك استخدامها لهذا الغرض.
PivotTable.formatAll () يطبق النمط على الجدول المحوري بأكمله أثناءPivotTable.format () يطبق النمط على خلية مفردة من الجدول المحوري.
يقوم نموذج التعليمات البرمجية التالي بتنسيق الجدول المحوري بأكمله بلون أزرق فاتح ثم تنسيق صف الجدول الثاني باللون الأصفر.
الجدول المحوري للإدخال قبل تنفيذ الكود
الجدول المحوري للإخراج بعد تنفيذ الكود
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
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, SaveFormat | |
# Create workbook object from source file containing pivot table | |
workbook = Workbook("pivotTable_test.xlsx") | |
# Access the worksheet by its name | |
worksheet = workbook.getWorksheets().get("PivotTable") | |
# Access the pivot table | |
pivotTable = worksheet.getPivotTables().get(0) | |
# Create a style object with background color light blue | |
style = workbook.createStyle() | |
style.setPattern(BackgroundType.SOLID) | |
style.setBackgroundColor(Color.getLightBlue()) | |
# Format entire pivot table with light blue color | |
pivotTable.formatAll(style) | |
# Create another style object with yellow color | |
style = workbook.createStyle() | |
style.setPattern(BackgroundType.SOLID) | |
style.setBackgroundColor(Color.getYellow()) | |
# Format the cells of the first row of the pivot table with yellow color | |
columns = [0, 1, 2, 3, 4] | |
for x in columns: | |
pivotTable.format(1, x, style) | |
# Save the workbook object | |
workbook.save("out.xlsx") | |
jpype.shutdownJVM() |