Select to view content in your preferred language

Report generation - Conditional cell formating

993
3
Jump to solution
10-22-2024 05:27 AM
RemyOlive
Occasional Contributor

Hi everyone,

I've starting working on report generation from the Survey123 website, and would like to be able to color-code cells from tables based on the value submitted on the Survey123 form.

So far I've been able to conditionnaly change the color of the text with $IF statements, but it would be much better if I could color the whole cell instead of just the text.

I saw a few similar questions being asked between 2020 and 2023, but no answer has been provided, maybe it's just not possible ?

If anyone found a way of doing this, help would be much appreciated ! 

Thanks,

Rémy

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DuncanC
Frequent Contributor

Nothing I'm finding is a good example.  There always is more going on that is either a client's IP or just will add confusion.

Step one is getting the data.  The two options I've explored are using the ESRI python library and just using the REST API directly.  There is a performance hit using the library but it does make things a little easier so I'd recommend it to start.  The documentation is decent:

https://developers.arcgis.com/python/latest/


It's well worth the time to learn,  once you have it in your toolkit you'll end up using it all the time, it's super handy.

Then I use python-docx as a library to create the docs.  Their documentation is great and the syntax is really straightforward.

https://python-docx.readthedocs.io/en/latest/

If you want to add charts I use seaborn.  And for nicer handling of table data I quite often use pandas.  But to start if you aren't familiar with them I'd just get the first two working first.

Feel free to ask any questions if you get stuck.

View solution in original post

0 Kudos
3 Replies
DuncanC
Frequent Contributor

For that level of complexity in your output I'd write a python script to take the data and put it into docx as desired.  I know it's not a lot of complexity.  You could do it in the report templates, but only if the cell being colored stands all by itself and might as well not be a cell.  Because of how the attribute data works in word it's awful to try to work with using the templates. As far as I know the only option would be to replace the entire table in your various cases, not just the cell that needs to be colored, and that doesn't work if the rest of the table isn't static.

As soon as there is anything that isn't 100% straight forward it's way faster/easier/better to just roll your own document output than try to make the report templates do what you want IMO.  To do it again I wouldn't bother learning the report templates feature at all, wasn't worth the little bit of time I put into it.  Should have just written python-docx scripts to handle everything, even the simple cases.

0 Kudos
RemyOlive
Occasional Contributor

Hi Duncan,

Thanks for the reply, I thought this might be the kind if answer I would get, as the report templates seem very static. Would you mind sharing some example of a python-docx template ? I have never touched on this so a starting point would be pretty useful. 

Thanks so much,

Rémy

0 Kudos
DuncanC
Frequent Contributor

Nothing I'm finding is a good example.  There always is more going on that is either a client's IP or just will add confusion.

Step one is getting the data.  The two options I've explored are using the ESRI python library and just using the REST API directly.  There is a performance hit using the library but it does make things a little easier so I'd recommend it to start.  The documentation is decent:

https://developers.arcgis.com/python/latest/


It's well worth the time to learn,  once you have it in your toolkit you'll end up using it all the time, it's super handy.

Then I use python-docx as a library to create the docs.  Their documentation is great and the syntax is really straightforward.

https://python-docx.readthedocs.io/en/latest/

If you want to add charts I use seaborn.  And for nicer handling of table data I quite often use pandas.  But to start if you aren't familiar with them I'd just get the first two working first.

Feel free to ask any questions if you get stuck.

0 Kudos