ph_table icon indicating copy to clipboard operation
ph_table copied to clipboard

Conditions in table: Colours do not appear in mail

Open danieldeconinck opened this issue 3 years ago • 4 comments

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: Screenshot 2021-12-02 at 14 17 40

Then I drop the table in my mail with the following code: Screenshot 2021-12-02 at 14 17 09

But I get this in my mail. I don't get colours Screenshot 2021-12-02 at 14 15 32

The generated HTML code for the first line of the table is Screenshot 2021-12-02 at 14 22 51

What do I do wrong?

Tx, Daniel

danieldeconinck avatar Dec 02 '21 13:12 danieldeconinck

Hello @danieldeconinck ,

Could you please provide me with a dummy example (not pictures) so I can easily replicate your issue?

Thanks!

sbi-rviot avatar Jan 05 '22 09:01 sbi-rviot

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.

Sm4o avatar Apr 13 '22 11:04 Sm4o

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 ?

Gypsying avatar Oct 28 '22 10:10 Gypsying

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

justin-mills-fws avatar Mar 14 '24 22:03 justin-mills-fws