Why does attempt to color ranges in a PivotTable have no effect?

It doesn’t work for me; if I color everything (as a test), it hoses the data up.


If I try to color just one cell (as a test), it colors row 258. This is the code:
// This colored up row 258…?!?
//var style2 = pivotTableSheet.Cells[9, 1].GetStyle();
//style2.BackgroundColor = Color.Red;
//style2.Pattern = BackgroundType.Solid;
//pivot.Format(9, 1, style2);

// This does the same thing (reds up row 258)
var style2 = pivotTableSheet.Cells[9, 1].GetStyle();
style2.BackgroundColor = Color.Red;
style2.Pattern = BackgroundType.Solid;
pt.Format(9, 1, style2);

…and here is a screenshot of the result (below)

Here is the current complete method:

private void ColorizeContractItemBlocks(List contractItemDescs)
{
int FIRST_DESCRIPTION_ROW = 7;
int DESCRIPTION_COL = 0;
int ROWS_BETWEEN_DESCRIPTIONS = 4;
var pivot = pivotTableSheet.PivotTables[0];
var dataBodyRange = pivot.DataBodyRange;
int currentRowBeingExamined = FIRST_DESCRIPTION_ROW;
int rowsUsed = dataBodyRange.EndRow;

pivot.RefreshData();
pivot.CalculateData();

PivotTable pt = pivotTableSheet.PivotTables[0];
var style = workBook.CreateStyle();
// Loop through PivotTable data, colorizing contract items
while (currentRowBeingExamined < rowsUsed)
{
Cell descriptionCell = pivotTableSheet.Cells[currentRowBeingExamined, DESCRIPTION_COL];
String desc = descriptionCell.Value.ToString();
if (contractItemDescs.Contains(desc))
{
style.BackgroundColor = CONTRACT_ITEM_COLOR;
style.Pattern = BackgroundType.Solid;

pt.Format(currentRowBeingExamined, 0, style);
pt.Format(currentRowBeingExamined, 1, style);
CellArea columnRange = pt.ColumnRange;
for (int c = columnRange.StartColumn; c <= columnRange.EndColumn; c++)
{
pt.Format(currentRowBeingExamined, c, style);
pt.Format(currentRowBeingExamined+1, c, style);
pt.Format(currentRowBeingExamined+2, c, style);
pt.Format(currentRowBeingExamined+3, c, style);
}

// This colored up row 258 or so…?!?
//var style2 = pivotTableSheet.Cells[9, 1].GetStyle();
//style2.BackgroundColor = Color.Red; // CONTRACT_ITEM_COLOR; //Color.Beige;
//style2.Pattern = BackgroundType.Solid;
//pivot.Format(9, 1, style2);

// This does the same thing (reds up row 258)
var style2 = pivotTableSheet.Cells[9, 1].GetStyle();
style2.BackgroundColor = Color.Red; // CONTRACT_ITEM_COLOR; //Color.Beige;
style2.Pattern = BackgroundType.Solid;
pt.Format(9, 1, style2);
}
currentRowBeingExamined = currentRowBeingExamined + ROWS_BETWEEN_DESCRIPTIONS;
}
}

Hi,


Which version of the product you are using? Please try using our latest version/fix: Aspose.Cells v16.11.8 (attached). Also try using the exact code (pasted in my previous reply) with the template file “HILTON±+Produce+Usage±+from+Oct+2015_PROCESSED_1323.xlsx” and let us know how it goes?

Thank you.

I am not using Java; I am targeting .NET. I am using the latest version available via NuGet in Visual Studio.

Hi,


Sorry for the mistake. I have re-attached the correct version (latest fix (.NET 2.0 and .NET 4.0 compiled versions)) now, please download it from my previous post here:
https://forum.aspose.com/t/23090

Thank you.

@cshannon,

This is to inform you that your issue (Ticket ID: “CELLSNET-44955”) has been resolved. We have fixed the formatting issue for the pivot table. The fix/enhancement will be included in our upcoming release (Aspose.Cells v24.8), which we plan to release before the end of this week. You will be notified once the new version is published.

You may try the following sample lines of code with the new version once it becomes available.
e.g.,

pivotTable.PivotFormats.FormatArea(PivotFieldType.Row, 0, PivotFieldSubtotalType.None, PivotTableSelectionType.DataAndLabel, false, false, style);
pivotTable.PivotFormats.FormatArea(PivotFieldType.Row, 1, PivotFieldSubtotalType.None, PivotTableSelectionType.DataAndLabel, false, false, style) 

The issues you have found earlier (filed as CELLSNET-44955) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi