Free Support Forum - aspose.com

Applying styles of conditional formatting to the spreadsheet

Hi,



Is it possible to add a function named ApplyFormat() in the FormatConditions class? This function would go through the sheet and apply styles to cells that satisfy the conditional format.



I’m guessing that you guys already have a private method to do this since SheetToImage() preserves conditional formatting.



The reason we need this is because we work alot with the OWC (Office Web Component) spreadsheet which supports importing through SpreadsheetML.



However, the OWC doesn’t support conditional formatting and so despite it being supported by Aspose’s SpreadsheetML, the formatting doesn’t show…



-Steve

Hi,

Aspose.Cells supports to preserve conditional formattins when saving the file as SpreadsheetML.

To apply formattings to the cells that satisfy the conditional formattings, you may utilize FormatCondition.Style API.

E.g.,

..........

int index = worksheet.ConditionalFormattings.Add();

FormatConditions fcs = worksheet.ConditionalFormattings[index];

FormatCondition fc = fcs[conditionIndex];

fc.Style.BackgroundColor = Color.Red;

For complete reference, please check the documentation topic:

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/conditional-formatting.html

Thank you.

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please try the attached version.

The conditional formatting feature of SpreadsheetXml file format is supported now.

Thank you.

Does this mean that I would need to:



1) Go through a range cell-by-cell to determine which FormatCondition it satisfies.



2) Apply FormatCondition.Style on the cells that satisfies the format condition.



Are there more effective ways of doing this? We are worried about performance.



-Steve

Hi Steve,

After look into this issue, we will add Cell.DisplayStyle property to get the display style of the cell.

Thanks for the help so far guys.



Excuse me for my lack of knowledge. How will a Cell.DisplayStyle property help with the issue I am having? Can we not use Cell.Style to achieve the same thing? Or is Cell.Style never meant to be use for assigning styles?



-Steve

Hi Steve,

We will get back to you to explain you further.

Thank you.

Hi Steve,

The Cell.DisplayStyle will be same as the format you see in MS Excel. If you export the file to OWC , you should use DisplayStyle,the Cell.Style property will be useless.

Just wondering also.



If we are to assign DisplayStyle cell-by-cell to the same style object, would this create a style object for each cell? For example, if I have a single bold style and apply it to 10,000 cells through Cell.DisplayStyle(), would this create 10,000 styles? If it does, this would cause performance problems.



Thanks guys

-Steve

Hi Steve,

Could you post a simple project show what you want to do?

In Aspose.Cells, we do not store the display style object in our class model. We will re-calculate the display style when you call Cell.DisplayStyle,because we do not want to change the original style and the display will be changed if you change the cell value. And if you want to set style to cell , please use Cell.SetStyle() method, we will check whether it is same as one of the inner style list.If not exist, we will add it to inner list.We only store a style index in the cell.

By the way, we will return a new style object in Cell.GetStyle() method.We could not return reference of the inner style,because all other cells will be changed if the style is changed.

I do not know OWC . If you set Cell.DisplayStyle to the cell of OWC and OWC does not gather a style list, i think you have to gather a list yourlself.

Hi,



Could you describe what the differences are between Cell.Style and Cell.GetStyle()/Cell.SetStyle()?



I am still having trouble understanding what DisplayStyle is being used for and why styles need to recalculated.



Thanks,

-Steve

Hi Steve,

Could you describe what the differences are between Cell.Style and Cell.GetStyle()/Cell.SetStyle()?
Please check the article for your reference: http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/evaluating-cell-getstyle-setstyle-methods-against-cell-style-property.html

We can brief you further about DisplayStyle if still needed.

Thank you.

So … I’m guessing that DisplayStyle would re-calculate the cell style depending if it satisfies any conditional format? That’ll be perfect if that’s the case.



-Steve

Hi Steve,

Please try this fix.

We have added a method Cell.GetDisplayStyle() method.

Works amazing, thanks for the work guys!



-Steve