DataBar Conditional Formatting in PivotTable

Hi guys,


Using v7.1.2.2 of Aspose, trying to get a simple PivotTable to display some conditional formatting.

I specifically need to display a DataBar, any Databar, however when i try to save the file, I get an error. I have duplicated the exception in the code below.

Workbook workbook = new Workbook();
//Create data source Table1
Worksheet worksheet = workbook.Worksheets[0];

worksheet.Cells[0, 0].Value = “Header1”;
worksheet.Cells[0, 1].Value = “Header2”;
worksheet.Cells[0, 2].Value = “Header3”;

for (int i = 1; i < 21; i++)
{
int value = i - 1;
worksheet.Cells[i, 0].Value = “Value1-” + (value < 10 ? “a” : “b”);
worksheet.Cells[i, 1].Value = “Value2-” + value;
worksheet.Cells[i, 2].Value = value;
}

worksheet.ListObjects.Add(0, 0, 20, 2, true);

//Create PivotTable
workbook.Worksheets.Add(“PivotSheet”);
worksheet = workbook.Worksheets[1];

int index = worksheet.PivotTables.Add("=Sheet1!A1:C21", “A1”, “PT”);
PivotTable pivotTable = worksheet.PivotTables[index];

pivotTable.AddFieldToArea(PivotFieldType.Row, “Header1”);
pivotTable.AddFieldToArea(PivotFieldType.Row, “Header2”);
pivotTable.AddFieldToArea(PivotFieldType.Data, “Header3”);

var fc = pivotTable.PivotFormatConditions[pivotTable.PivotFormatConditions.Add()];
fc.ScopeType = PivotConditionFormatScopeType.field;

FormatConditionCollection fcs = fc.FormatConditions;
CellArea area = new CellArea
{
StartRow = 1,
EndRow = 1,
StartColumn = 2,
EndColumn = 2
};
FormatCondition condition = fcs[fcs.Add(area, FormatConditionType.DataBar, OperatorType.Equal, “”, “”)[0]];
condition.Type = FormatConditionType.DataBar;

condition.DataBar.MinCfvo.Type = FormatConditionValueType.Number;
condition.DataBar.MinCfvo.Value = 0;
condition.DataBar.MaxCfvo.Type = FormatConditionValueType.Number;
condition.DataBar.MaxCfvo.Value = 1;
condition.DataBar.Color = Color.Green;
condition.DataBar.ShowValue = true;

workbook.Save(“TestPivot.xlsx”);

A little help please?

Hi,


Please download and try the latest fix: Aspose.Cells for .NET (Latest Version)
I have tested it with your code, it works fine as I don’t get any exception.

Thank you.

Amjad,


Yes, that’s true, thank you.

However, the code above still does not produce any conditional formatting. If I check it, there’s no conditional formatting rules anywhere on the spreadsheet at all.

Is this a problem with my usage? Can you provide some guidance as to how I can get a databar to appear for values in the third column?

Regards,
Seb

Hi,

I can notice the issue as you have mentioned. The conditional formatting is not applied to the pivot table field values. I even tried to call RefreshData and CalculateData methods of pivot table etc.

I have logged a ticket for your issue with an id: CELLSNET-40688. We will look into your issue soon.

Thank you.

Hi,


We have fixed this issue. Please download and use this latest fix of Aspose.Cells for .NET (Latest Version) , and let us know your feedback.

Hi,


For the test code that I have supplied, when I run it using the 7.2.1.4 version, the conditional formatting is still not applied.

Can you please provide me with the sample code you have used to produce the conditional formatting?

Regards,
Seb

Hi,

Thanks for your input.

I noticed, you are right. I have tested your code with the latest version:
Aspose.Cells for .NET (Latest Version)

I am attaching the output xlsx file.

Could you please download it and manually rectify it by applying your conditional formattings and save it with different name? We need your expected output file, it will help us quickly sort out your issue.

Also, I have logged your comment against the issue id: CELLSNET-40688

Below is a screenshot for a reference.

Screenshot:

Thanks for the speedy response.


I have attached a version of the output spreadsheet that has an example of the databar formatting that I would expect my code to generate.

However, my code could be incorrect. A better question could be:

What code do I have to use to generate the conditional formatting on the pivot table, as shown in TestPivot-Expected.xlsx?

Cheers,
Seb

Hi,

Thank you for providing the expected output file.

We will soon look into it and provide you a sample code. If there is some bug, we will fix it and let you know asap.

Below is a screenshot for a reference.

Screenshot:

Hi,

We are working over your issue and we will try to support the data bar conditional formatting in the pivot table before the end of this month. Once it is supported, we will let you know here.

Thank you.

Hi,

Please download and try this fix: Aspose.Cells for .NET (Latest Version)

This issue is fixed in the latest aspose version

sample code:

var fc = pivotTable.PivotFormatConditions[pivotTable.PivotFormatConditions.Add()];
fc.ScopeType = PivotConditionFormatScopeType.data;

FormatConditionCollection fcs = fc.FormatConditions;
CellArea area = new CellArea
{
StartRow = 1,
EndRow = 1,
StartColumn = 2,
EndColumn = 2
};

FormatCondition condition = fcs[fcs.Add(area, FormatConditionType.DataBar, OperatorType.Equal, "", "")[0]];
condition.Type = FormatConditionType.DataBar;
DataBar bar = condition.DataBar;
bar.MinLength = 0;
bar.MaxLength = 100;
bar.MinCfvo.Type = FormatConditionValueType.AutomaticMin;
bar.MinCfvo.Value = 0;
bar.MaxCfvo.Type = FormatConditionValueType.AutomaticMax;
bar.MaxCfvo.Value = 1;
bar.Color = Color.FromArgb(99,195,132);
bar.ShowValue = true;
bar.BarBorder.Type = DataBarBorderType.DataBarBorderSolid;
bar.BarBorder.Color = Color.FromArgb(99, 195, 132); ;

bar.BarFillType = DataBarFillType.DataBarFillGradient;




The issues you have found earlier (filed as CELLSNET-40688) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.