Free Support Forum - aspose.com

Problem with set style.Font.Color = style.ForegroundColor(Hide Data)

Hi,
I need hide data in a cell(font and foreground colors the same).

But if Foreground color ==Color.Empty set operator is ignored by the Font object

Example:
var workbook = new Workbook(“C:\test.xlsx”);
Cells cells = workbook.Worksheets[0].Cells;

cells[1, 1].Value = 12345;
var style = cells[1, 1].GetStyle();
style.Font.Color = style.ForegroundColor;
cells[1, 1].SetStyle(style, new StyleFlag {FontColor = true});

My thoughts:
Aspose API thinks if I set Color.Empty to Font.Color that I set AutoColor(I review implementation of Font.Color property). That is incorrect. May be you add something like
Color? RawColor{get{…}set{…}} where null value means AutoColor

I’m intresting to buy Aspose.Cells, but few problems(this is one of them) stop me

Please, advise

Hi,

Thanks for your consideration for Aspose.Cells for .NET.

You can set your Font.Color to white, if you found that background color is empty. If the background color is not empty than you can set the Font.Color to the background color of the cell. I think, it should be sufficient for your needs.

Thank you,
but it’s only a workaround.

It’s not the same as in Excel Automation.
Please can you add this suggestion(about Font.RawColor) to your bug tracking system

Hi,

Sure, I will forward your post to development team, if they found it as a useful feature, they will surely add it and we will let you know asap.

Thanks a lot!

Hi,

Please try the following code to hide your data.

C#


Cells cells = workbook.Worksheets[0].Cells;


cells[1, 1].Value = 12345;


var style = cells[1, 1].GetStyle();


switch (style.Pattern)

{


case BackgroundType.None:


style.Font.Color = Color.White;


break;


default:


if (style.ForegroundColor == Color.Empty)


style.Font.Color = Color.White;


else


style.Font.Color = style.ForegroundColor;


break;


}


cells[1, 1].SetStyle(style, new StyleFlag { FontColor = true });