Coloring HTML table cells from “Low to High Color Shades” depending on Cell Value in Python HTML Email

瘦欲@ 提交于 2019-12-11 06:58:22

问题


I am using HTML-Email with HTML Table within - Python MIME type : text/html Email with below code :

dashboardTable = """ <table>"""       
indexCount = 1
for sectionIndex in  range(0,len(sections_available)):
   dashboardTable = dashboardTable + """
      <tr>
          <td align='left'>""" + str(indexCount) + """  </td>
          <td align='left'>""" + sections_available[sectionIndex] + """  </td>
          <td align='left'> """ + str(sections_timeTaken[sectionIndex]) + """ </td>
     </tr>"""
   indexCount = indexCount + 1

dashboardTable = dashboardTable + """</table>"""

I need to color Third Cell:

<td align='left'> """ + str(sections_timeTaken[sectionIndex]) + """ </td>

In a way such that, Highest sections_timeTaken value kept with "Red Color" to lowest in "Green Color". Coloring entire range of values in ordered manner from Highest to Lowsest :

Like Red -> Light red -> Lightesr Red -> Yellow - > Green eventually.[ Not mentioning exact shade]

The total number of Values to be plotted inside table will remain dynamic.

I am using Python HTML table within Email.


回答1:


I think this would be easier to work with in HSL, at least for setting up your color values. That way you can work with one counter per h-s-l in a 0-1 range versus setting up a bunch of points in hexadecimal to fade up to / down from and addressing them via an array.

Luckily there's a good python library for color format conversion: https://pypi.python.org/pypi/colour/0.0.5

should be pretty easy to work that into your code i reckon.



来源:https://stackoverflow.com/questions/28060644/coloring-html-table-cells-from-low-to-high-color-shades-depending-on-cell-valu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!