ph_table
ph_table copied to clipboard
Conditions in table: Colours do not appear in mail
Hi, Tx for your work on adding conditions on numbers. However, I seem to have an issue with it.
I am building a table with the following code:
Then I drop the table in my mail with the following code:
But I get this in my mail. I don't get colours
The generated HTML code for the first line of the table is
What do I do wrong?
Tx, Daniel
Hello @danieldeconinck ,
Could you please provide me with a dummy example (not pictures) so I can easily replicate your issue?
Thanks!
I think there's an issue at line 184 in pretty_html_table.py:
int(repr(line).split('>')[1].split('<')[0]) < conditions[k]['min']
For values like Daniel's case that are float this would throw an error. It's happening on my end as well. A solution is to use float()
instead. I'll create a PR when I can.
I think there's an issue at line 184 in pretty_html_table.py:
int(repr(line).split('>')[1].split('<')[0]) < conditions[k]['min']
For values like Daniel's case that are float this would throw an error. It's happening on my end as well. A solution is to use
float()
instead. I'll create a PR when I can.
Any progress ?
I had this issue as well when emailing to the newer Outlook Web Access client (from ArcGIS Online). In my case at least, the problem is that in the <td style = "xxxxxxx">
and <th style = "xxxxxxx">
tags the spaces around the =
sign (as in after style
and before the double-quote mark) cause Outlook to strip all the formatting out of <td>
or <th>
tags.
The HTML5 spec says the attribute name is followed by zero or more spaces, but Outlook has other ideas about what's right.
I narrowed this down to be the problem after a bunch of testing, and fixed my output by adding code to post-process the HTML generated by build_table()
by replacing style = "...
with style="...
. After the replacement, emailed tables render correctly in Outlook Web.
For example:
from pretty_html_table import build_table
# Create temporary data table
data_dict = {'Column 1': [1, 2, 3, 4, 5], 'Column 2': ['A' ,'B', 'C', 'D', 'E']}
sample_df = pd.DataFrame(data=data_dict)
sample_df_html = build_table(
df = sample_df,
color = 'grey_light'
)
# This line fixes the spacing that breaks Outlook's web client by removing the
# space characters on either side of the =
sample_df_html = sample_df_html.replace("style = ", "style=")
print(sample_df_html)
This spacing occurs pretty consistently, such as:
https://github.com/sbi-rviot/ph_table/blob/dab179590e33ccf751994bd8ef96bfe951319f01/pretty_html_table/pretty_html_table.py#L64
https://github.com/sbi-rviot/ph_table/blob/dab179590e33ccf751994bd8ef96bfe951319f01/pretty_html_table/pretty_html_table.py#L144