PivotTablo alanının GörünenAdı ile Hücre nesnesini alın
Contents
[
Hide
]
Aspose.Cells, pivot alanının görünen adı ile hücre nesnesine erişmek için PivotTable.getCellByDisplayName() yöntemini sağlar. Bu yöntem, pivot alanı başlığını vurgulamak veya biçimlendirmek istediğinizde kullanışlıdır. Bu makale, veri alanının görünen adını almak ve ardından bu alana biçimlendirme uygulamak nasıl açıklar.
PivotTablo Alanının Görünen Adı ile Hücre Nesnesi Alın
Aşağıdaki kod, çalışma sayfasının ilk pivot tablosuna erişir ve ardından pivot tablosunun ikinci veri alanının görünen adı ile hücreyi alır. Ardından hücrenin dolgu rengini mavi ve yazı tipi rengini siyah olarak değiştirir. Aşağıdaki ekran görüntüleri, kodun çalıştırılması öncesinde ve sonrasında pivot tablosunun nasıl göründüğünü gösterir.
Pivot Tablosu - Önce
Pivot Tablosu - Sonra
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetCellObject.class); | |
// Create workbook object from source excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access first pivot table inside the worksheet | |
PivotTable pivotTable = worksheet.getPivotTables().get(0); | |
// Access cell by display name of 2nd data field of the pivot table | |
String displayName = pivotTable.getDataFields().get(1).getDisplayName(); | |
Cell cell = pivotTable.getCellByDisplayName(displayName); | |
// Access cell style and set its fill color and font color | |
Style style = cell.getStyle(); | |
style.setForegroundColor(Color.getLightBlue()); | |
style.getFont().setColor(Color.getBlack()); | |
// Set the style of the cell | |
pivotTable.format(cell.getRow(), cell.getColumn(), style); | |
// Save workbook | |
workbook.save(dataDir + "output.xlsx"); |