Skip to main content
Solved

Styling Excel cells in the Writer


erik_jan
Contributor
Forum|alt.badge.img+18

Hi all,

I have read that the Excel writer supports colors for font and background.

What I can not find is how.

I have this scenario:

Based on the value of an attribute ("Yes" or "No") I want to color the font (or background) black (if "Yes") and red (if "No").

I would use the Conditional Values in the AttributeCreator, but can not find what to set for the color.

Is this possible, and if Yes how.

Any help is appreciated.

Erik Jan

Best answer by ebygomm

You cannot do this in 2016, I don't know whether the enhancement mentioned here made it into 2017

https://knowledge.safe.com/questions/30191/insert-color-in-attribute-names-in-xls.html

View original
Did this help you find an answer to your question?

14 replies

ebygomm
Influencer
Forum|alt.badge.img+38
  • Influencer
  • Best Answer
  • April 3, 2017

You cannot do this in 2016, I don't know whether the enhancement mentioned here made it into 2017

https://knowledge.safe.com/questions/30191/insert-color-in-attribute-names-in-xls.html


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • April 3, 2017

I wish this would be an option:

Use a @Value(my_color) to set the font color of a cell:

Tried this in FME 2016.1 and 2017.0.

But not (yet) available.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • April 3, 2017
erik_jan wrote:

I wish this would be an option:

Use a @Value(my_color) to set the font color of a cell:

Tried this in FME 2016.1 and 2017.0.

But not (yet) available.

I added this as an Idea:

 

https://knowledge.safe.com/idea/42340/styling-cells-in-excel-based-on-an-attribute-value.html

 

 


ebygomm
Influencer
Forum|alt.badge.img+38
  • Influencer
  • April 3, 2017

As a workaround it is not possible to have a conditional format set in a template file to do the styling?


redgeographics
Celebrity
Forum|alt.badge.img+49

I've done it by setting a custom number format, using a color name between straight brackets, e.g. [red] to get red text.


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • April 4, 2017

You could create the variables etc. and construct a batch file which calls a vb script and save it using a featurewriter.

The vb script sets your colours, font format etc.

SystemCaller would then be used to start the bat.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • April 4, 2017
redgeographics wrote:

I've done it by setting a custom number format, using a color name between straight brackets, e.g. [red] to get red text.

Hi @redgeographics, can you explain what you mean with setting a custom number format?

 


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • April 4, 2017
redgeographics wrote:

I've done it by setting a custom number format, using a color name between straight brackets, e.g. [red] to get red text.

I think I found it.

 

But again: this only allows hard-coded values (like [red]) and will not take it from an attribute.

 

That will not get an error in FME, but does not allow you to open the xlsx file in Excel without errors.

 

 


redgeographics
Celebrity
Forum|alt.badge.img+49
erik_jan wrote:
I think I found it.

 

But again: this only allows hard-coded values (like [red]) and will not take it from an attribute.

 

That will not get an error in FME, but does not allow you to open the xlsx file in Excel without errors.

 

 

It looks like Excel is limited to a palette of 56 colors for cells (and grid lines for that matter). I tried to get it to accept RGB or HTML color codes but no luck, results varied from opening with lots of errors to changing the value in the cell!

 

 


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • April 6, 2017

@erik_jan

@redgeographics

Only the palette is limited.

Not excel. You can extract and place celcolor. Using VisualBasicfoApplications

Here are some parts form some VB scripts I made (with the help of the for a and Microsoft helpfile on VBA of course)

Extract cellcolor:

cellcolor from cell in r,g,b

Function CelRGB2(MyRef As Range) As Variant

 

CelCol = MyRef.Interior.Color

 

CelRGB2 = (CelCol Mod 256) & ", " & ((CelCol \\ 256) Mod 256) & ", " & (CelCol \\ 65536)

 

End Function

------------------------

Place celcolor based on R,G,B:

Sub SerRGB3()

CelCol = ActiveCell.Offset(0, -1).Value

R = (CelCol Mod 256)

 

G = ((CelCol \\ 256) Mod 256)

 

B = (CelCol \\ 65536)

 

 

colmn = Split(ActiveCell.Address, "$")(1)

 

MyRef = "A" & ActiveCell.Row & ":" & colmn & ActiveCell.Row

 

Range(FormulaRange).Interior.Color = RGB(R, G, B)

 

End Sub

------------------


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • April 7, 2017

Thank you all for your answers.

I still believe it would be a huge improvement if the color could be set per attribute and in doing so would allow a color setting per cell.


philippeb
Enthusiast
Forum|alt.badge.img+20
  • Enthusiast
  • June 28, 2017

me too i would love that!


tibor
Participant
Forum|alt.badge.img+2
  • Participant
  • January 17, 2018

In FME 2018 (currently beta) looks like this problem is solved.

I tested it and looks very promising. Via an new transformer it's possible to style one of more cel's. But you can also do this with an attributecreator or an Pythoncaller. So styling in Excel will be much more versatible.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • January 17, 2018
tibor wrote:

In FME 2018 (currently beta) looks like this problem is solved.

I tested it and looks very promising. Via an new transformer it's possible to style one of more cel's. But you can also do this with an attributecreator or an Pythoncaller. So styling in Excel will be much more versatible.

Thanks, @tibor,

 

I noticed the same during the FME 2018 webinar.

 

Looks good and I will try it, when I get another project that requires this.

 

Erik

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings