Cell nesnesini, PivotTable'ın PivotField'inin DisplayName'i ile alın
Contents
[
Hide
]
Aspose.Cells sağlarPivotTable.GetCellByDisplayName()pivot alanının görünen adına göre hücre nesnesine erişmek için kullanabileceğiniz yöntem. Bu yöntem, pivot alan başlığınızı vurgulamak veya biçimlendirmek istediğinizde kullanışlıdır. Bu makalede, veri alanının görünen adına göre hücre nesnesinin nasıl alınacağı ve ardından ona biçimlendirmenin nasıl uygulanacağı açıklanmaktadır.
Cell nesnesini, PivotTable’ın PivotField’inin DisplayName’i ile alın
Aşağıdaki kod, çalışma sayfasının ilk pivot tablosuna erişir ve ardından pivot tablonun ikinci veri alanının görünen adına göre hücre alır. Daha sonra hücrenin dolgu rengini ve yazı tipi rengini sırasıyla açık mavi ve siyah olarak değiştirir. Aşağıdaki ekran görüntüleri, pivot tablonun kodun yürütülmesinden önce ve sonra nasıl göründüğünü gösterir.
Pivot Tablo - Önce |
---|
![]() |
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 from source excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first pivot table inside the worksheet | |
PivotTable pivotTable = worksheet.PivotTables[0]; | |
// Access cell by display name of 2nd data field of the pivot table | |
Cell cell = pivotTable.GetCellByDisplayName(pivotTable.DataFields[0].DisplayName); | |
// Access cell style and set its fill color and font color | |
Style style = cell.GetStyle(); | |
style.ForegroundColor = Color.LightBlue; | |
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"); |
Pivot Tablo - Sonra |
---|
![]() |