تنسيق خلايا جدول البيانات المحورية
في بعض الأحيان، قد ترغب في تنسيق خلايا الجدول المحوري. على سبيل المثال، قد ترغب في تطبيق لون خلفية على خلايا الجدول المحوري. توفر Aspose.Cells طريقتين PivotTable.FormatAll() و PivotTable.Format() يمكنك استخدامهما لهذا الغرض.
PivotTable.FormatAll() تطبق النمط على جدول المحور بأكمله بينما PivotTable.Format() يطبق النمط على خلية واحدة في جدول المحور.
الشيفرة النموذجية التالية تحمل ملف Excel النموذجي الذي يحتوي على جدولين محوريين، وتحقق عملية تنسيق جدول المحور بأكمله وتنسيق الخلايا الفردية في جدول المحور.
// Create workbook object from source file containing pivot table | |
Workbook workbook = new Workbook("pivot_format.xlsx"); | |
// Access the worksheet by its name | |
Worksheet worksheet = workbook.Worksheets["Sheet1"]; | |
// Access the pivot table | |
PivotTable pivotTable = worksheet.PivotTables[1]; | |
// Create a style object with background color light blue | |
Style style = workbook.CreateStyle(); | |
style.Pattern = BackgroundType.Solid; | |
style.BackgroundColor = Color.LightBlue; | |
// Format entire pivot table with light blue color | |
pivotTable.FormatAll(style); | |
// Create another style object with yellow color | |
style = workbook.CreateStyle(); | |
style.Pattern = BackgroundType.Solid; | |
style.BackgroundColor = Color.Yellow; | |
// Access the pivot table | |
PivotTable pivotTable2 = worksheet.PivotTables[0]; | |
// Format the cell of pivot table | |
pivotTable2.Format(16, 5, style); | |
// Save the workbook object | |
workbook.Save("out.xlsx"); |