How can I add an html colored square inside a Table cell?
Asked by llatore:

The new confluence format for tables has gotten rid of adding a colored background to table cells and has messed up my file.

Does anyone know how to add a color in there using the html iframe or something similar?

Im just looking to add a square in html that I can change the hex value to.


Answers:
author: Katerina Kovriga {Stiltsoft}
body: Hi [@llatore](/t5/user/viewprofilepage/user-id/4139644) ,

You may try the [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?hosting=cloud&tab=overview) app and its [Table Transformer](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+Transformer+macro) macro with the wiki markup feature.

Wrap your table in the Table Transformer macro and use a custom SQL query to color your cells and/or text:

![TTTT 1.png](https://community.atlassian.com/t5/image/serverpage/image-id/115796i7D145F080BF85665/image-size/large?v=v2&px=999 "TTTT 1.png")![TTTT 2.png](https://community.atlassian.com/t5/image/serverpage/image-id/115797i09DA52CC49CAD1DC/image-size/large?v=v2&px=999 "TTTT 2.png")

SELECT  
FORMATWIKI("{cell:bgColor=yellow}" + T1.'Rep' + "{cell}") AS 'Rep',  
FORMATWIKI("{cell:bgColor=#FFE5B4}" + T1.'Department'+ "{cell}") AS 'Department',  
FORMATWIKI("{cell:bgColor=orange\|textColor=yellow}" + T1.'City'+ "{cell}") AS 'City',  
FORMATWIKI("{panel:bgColor=orange\|textColor=white}" + T1.'City'+ "{panel}") AS 'City 1',  
FORMATWIKI("{color:orange}" + T1.'City' + "{color}") AS 'City 2'  
FROM T1

![TTTT 3.png](https://community.atlassian.com/t5/image/serverpage/image-id/115801i4B6BDF805B78AB09/image-size/large?v=v2&px=999 "TTTT 3.png")

You can also use this macro for **conditional formatting** (like in Excel).

Here is an example of the possible SQL query and the obtained result:

SELECT  
T1.'Month',  
FORMATWIKI("{cell:bgColor=" +  
CASE WHEN T1.'Bread' \<= "100" THEN "#FA7E70"  
WHEN T1.'Bread' \> "100" AND T1.'Bread' \<= "200" THEN "#FFE784"  
ELSE "#8FCA7D"  
END  
+ "}" + "$" + T1.'Bread' + "{cell}")  
AS 'Bread',  
FORMATWIKI("{cell:bgColor=" +  
CASE WHEN T1.'Rolls' \<= "100" THEN "#FA7E70"  
WHEN T1.'Rolls' \> "100" AND T1.'Rolls' \<= "200" THEN "#FFE784"  
ELSE "#8FCA7D"  
END  
+ "}" + "$" + T1.'Rolls' + "{cell}")  
AS 'Rolls',  
FORMATWIKI("{cell:bgColor=" +  
CASE WHEN T1.'Cookies' \<= "100" THEN "#FA7E70"  
WHEN T1.'Cookies' \> "100" AND T1.'Cookies' \<= "200" THEN "#FFE784"  
ELSE "#8FCA7D"  
END  
+ "}" + "$" + T1.'Cookies' + "{cell}")  
AS 'Cookies',  
FORMATWIKI("{cell:bgColor=" +  
CASE WHEN T1.'Muffins' \<= "100" THEN "#FA7E70"  
WHEN T1.'Muffins' \> "100" AND T1.'Muffins' \<= "200" THEN "#FFE784"  
ELSE "#8FCA7D"  
END  
+ "}" + "$" + T1.'Muffins' + "{cell}")  
AS 'Muffins'  
FROM T\*

![TTTT 4.png](https://community.atlassian.com/t5/image/serverpage/image-id/115802i6333BF2478F13CCC/image-size/large?v=v2&px=999 "TTTT 4.png")

comments: author: llatore
body: That worked well. Thanks [@Katerina Kovriga {Stiltsoft}](/t5/user/viewprofilepage/user-id/1464746)


author: Kelly Hall
body: Formatwiki is not available on my companies version. Is there another method using transformer or CSS separately?


author: Katerina Kovriga {Stiltsoft}
body: Hi [@Kelly Hall](/t5/user/viewprofilepage/user-id/3978801) , what do you mean by the phrase that formatwiki is not available for your company? If you have our app with the Table Transformer macro, then the macro will understand formatwiki markup.

If the Table Transformer doesn't recognize these commands, it means that you use an old version of the app and you need to update it (it concerns Server and Data Center). For Cloud the app is always up-to-date.


author: Kelly Hall
body: Thank you for your response. Yes, I can use the table transformer macro but it gives me an error when I put in the formatwiki command line.

Short of getting the version update, is it possible to use a if then query?

I did see that an if then can render handy status results but I'd like to make the cell color-coded based on the date entered.

Thanks again.


author: Katerina Kovriga {Stiltsoft}
body: To work with the cells background, you need to update the app (FORMATWIKI was added in October, 2020).

The IF THEN query adds an additional column based on the second mini table inside the Table Transformer macro. It seems that you are referring to [this case](https://docs.stiltsoft.com/display/public/TFAC/Custom+Transformation+-+use+cases+with+advanced+SQL+queries#CustomTransformationusecaseswithadvancedSQLqueries-ComparingtwodatesusingIf/Thenconstruct).

But you can't work with the cells background and text color without the FORMATWIKI functionality. This feature was added specifically to cover the conditional formatting (for example, like you have in Excel).


author: Kelly Hall
body: ok. thank you for your help.


author: Kelly Hall
body: Formatwiki is not available on my companies version. Is there another method using transformer or CSS separately?


Tags: cloud

colour

confluence-cloud

table