Python 使用 win32com outlook 将样式化的数据框发送到电子邮件

Python styled dataframe to email using win32com outlook

下面是我的 python 代码的输出。数据框已设置样式并转换为 html 文件。

<style type="text/css">
#T_45521_row0_col3, #T_45521_row0_col4, #T_45521_row0_col5, #T_45521_row0_col6, #T_45521_row0_col8, #T_45521_row0_col9, #T_45521_row0_col10, #T_45521_row1_col3, #T_45521_row1_col4, #T_45521_row1_col5, #T_45521_row1_col6, #T_45521_row1_col8, #T_45521_row1_col9, #T_45521_row1_col10, #T_45521_row2_col3, #T_45521_row2_col4, #T_45521_row2_col5, #T_45521_row2_col6, #T_45521_row2_col8, #T_45521_row2_col9, #T_45521_row2_col10, #T_45521_row3_col3, #T_45521_row3_col4, #T_45521_row3_col5, #T_45521_row3_col6, #T_45521_row3_col8, #T_45521_row3_col9, #T_45521_row3_col10, #T_45521_row4_col3, #T_45521_row4_col4, #T_45521_row4_col5, #T_45521_row4_col6, #T_45521_row4_col8, #T_45521_row4_col9, #T_45521_row4_col10, #T_45521_row4_col11, #T_45521_row5_col3, #T_45521_row5_col4, #T_45521_row5_col5, #T_45521_row5_col6, #T_45521_row5_col8, #T_45521_row5_col9, #T_45521_row5_col10, #T_45521_row6_col3, #T_45521_row6_col4, #T_45521_row6_col5, #T_45521_row6_col6, #T_45521_row6_col8, #T_45521_row6_col9, #T_45521_row6_col10, #T_45521_row7_col3, #T_45521_row7_col4, #T_45521_row7_col5, #T_45521_row7_col6, #T_45521_row7_col8, #T_45521_row7_col9, #T_45521_row7_col10, #T_45521_row8_col3, #T_45521_row8_col4, #T_45521_row8_col5, #T_45521_row8_col6, #T_45521_row8_col8, #T_45521_row8_col9, #T_45521_row8_col10, #T_45521_row9_col3, #T_45521_row9_col4, #T_45521_row9_col5, #T_45521_row9_col6, #T_45521_row9_col8, #T_45521_row9_col9, #T_45521_row9_col10, #T_45521_row9_col11, #T_45521_row10_col3, #T_45521_row10_col4, #T_45521_row10_col5, #T_45521_row10_col6, #T_45521_row10_col8, #T_45521_row10_col9, #T_45521_row10_col10, #T_45521_row11_col3, #T_45521_row11_col4, #T_45521_row11_col5, #T_45521_row11_col6, #T_45521_row11_col8, #T_45521_row11_col9, #T_45521_row11_col10, #T_45521_row12_col3, #T_45521_row12_col4, #T_45521_row12_col5, #T_45521_row12_col6, #T_45521_row12_col8, #T_45521_row12_col9, #T_45521_row12_col10, #T_45521_row13_col3, #T_45521_row13_col4, #T_45521_row13_col5, #T_45521_row13_col6, #T_45521_row13_col8, #T_45521_row13_col9, #T_45521_row13_col10, #T_45521_row14_col3, #T_45521_row14_col4, #T_45521_row14_col5, #T_45521_row14_col6, #T_45521_row14_col8, #T_45521_row14_col9, #T_45521_row14_col10, #T_45521_row15_col3, #T_45521_row15_col4, #T_45521_row15_col5, #T_45521_row15_col6, #T_45521_row15_col8, #T_45521_row15_col9, #T_45521_row15_col10, #T_45521_row16_col3, #T_45521_row16_col4, #T_45521_row16_col5, #T_45521_row16_col6, #T_45521_row16_col8, #T_45521_row16_col9, #T_45521_row16_col10, #T_45521_row17_col3, #T_45521_row17_col4, #T_45521_row17_col5, #T_45521_row17_col6, #T_45521_row17_col8, #T_45521_row17_col9, #T_45521_row17_col10, #T_45521_row18_col3, #T_45521_row18_col4, #T_45521_row18_col5, #T_45521_row18_col6, #T_45521_row18_col8, #T_45521_row18_col9, #T_45521_row18_col10, #T_45521_row19_col3, #T_45521_row19_col4, #T_45521_row19_col5, #T_45521_row19_col6, #T_45521_row19_col8, #T_45521_row19_col9, #T_45521_row19_col10, #T_45521_row19_col11, #T_45521_row20_col3, #T_45521_row20_col4, #T_45521_row20_col5, #T_45521_row20_col6, #T_45521_row20_col8, #T_45521_row20_col9, #T_45521_row20_col10 {
  text-align: right;
  'border-spacing': '10px 50px';
}
#T_45521_row0_col7, #T_45521_row3_col7, #T_45521_row5_col7, #T_45521_row11_col7 {
  background: #0070c0;
  color: white;
  text-align: right;
}
#T_45521_row0_col11, #T_45521_row1_col11, #T_45521_row2_col11, #T_45521_row3_col11, #T_45521_row7_col11, #T_45521_row10_col11, #T_45521_row11_col11, #T_45521_row12_col11, #T_45521_row14_col11, #T_45521_row18_col11 {
  background: #c6efce;
  color: #006100;
  text-align: right;
}
#T_45521_row1_col7, #T_45521_row2_col7, #T_45521_row4_col7, #T_45521_row5_col11, #T_45521_row6_col7, #T_45521_row6_col11, #T_45521_row7_col7, #T_45521_row8_col7, #T_45521_row8_col11, #T_45521_row9_col7, #T_45521_row10_col7, #T_45521_row12_col7, #T_45521_row13_col7, #T_45521_row13_col11, #T_45521_row14_col7, #T_45521_row15_col7, #T_45521_row15_col11, #T_45521_row16_col7, #T_45521_row16_col11, #T_45521_row17_col7, #T_45521_row17_col11, #T_45521_row18_col7, #T_45521_row19_col7, #T_45521_row20_col7, #T_45521_row20_col11 {
  background: #ffbf00;
  text-align: right;
}
</style>
<table id="T_45521_" border="1" class="dataframe" style="border-collapse: collapse">
  <thead>
    <tr>
      <th class="col_heading level0 col0" >Date</th>
      <th class="col_heading level0 col1" >Scheme Name</th>
      <th class="col_heading level0 col2" >Scheme Code</th>
      <th class="col_heading level0 col3" >Equity Value</th>
      <th class="col_heading level0 col4" >Total AUM</th>
      <th class="col_heading level0 col5" >Equity %</th>
      <th class="col_heading level0 col6" >BM Allocation</th>
      <th class="col_heading level0 col7" >Effective %</th>
      <th class="col_heading level0 col8" >Large Cap</th>
      <th class="col_heading level0 col9" >Mid Cap</th>
      <th class="col_heading level0 col10" >Small Cap</th>
      <th class="col_heading level0 col11" >Mid+Small</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td id="T_45521_row0_col0" class="data row0 col0" >14-Dec-2021</td>
      <td id="T_45521_row0_col1" class="data row0 col1" >ANXX</td>
      <td id="T_45521_row0_col2" class="data row0 col2" >ANXX</td>
      <td id="T_45521_row0_col3" class="data row0 col3" >72</td>
      <td id="T_45521_row0_col4" class="data row0 col4" >1250</td>
      <td id="T_45521_row0_col5" class="data row0 col5" >5.74</td>
      <td id="T_45521_row0_col6" class="data row0 col6" >0</td>
      <td id="T_45521_row0_col7" class="data row0 col7" >0.00</td>
      <td id="T_45521_row0_col8" class="data row0 col8" >100</td>
      <td id="T_45521_row0_col9" class="data row0 col9" >0</td>
      <td id="T_45521_row0_col10" class="data row0 col10" >0</td>
      <td id="T_45521_row0_col11" class="data row0 col11" >0.34</td>
    </tr>
    <tr>
      <td id="T_45521_row1_col0" class="data row1 col0" >14-Dec-2021</td>
      <td id="T_45521_row1_col1" class="data row1 col1" >Group Gratuity Balanced Fund</td>
      <td id="T_45521_row1_col2" class="data row1 col2" >BALFND</td>
      <td id="T_45521_row1_col3" class="data row1 col3" >12</td>
      <td id="T_45521_row1_col4" class="data row1 col4" >50</td>
      <td id="T_45521_row1_col5" class="data row1 col5" >24.49</td>
      <td id="T_45521_row1_col6" class="data row1 col6" >25</td>
      <td id="T_45521_row1_col7" class="data row1 col7" >97.94</td>
      <td id="T_45521_row1_col8" class="data row1 col8" >85</td>
      <td id="T_45521_row1_col9" class="data row1 col9" >12</td>
      <td id="T_45521_row1_col10" class="data row1 col10" >3</td>
      <td id="T_45521_row1_col11" class="data row1 col11" >15.29</td>
    </tr>
    <tr>
      <td id="T_45521_row2_col0" class="data row2 col0" >14-Dec-2021</td>
      <td id="T_45521_row2_col1" class="data row2 col1" >Group Gratuity Growth Fund</td>
      <td id="T_45521_row2_col2" class="data row2 col2" >GRWFND</td>
      <td id="T_45521_row2_col3" class="data row2 col3" >13</td>
      <td id="T_45521_row2_col4" class="data row2 col4" >27</td>
      <td id="T_45521_row2_col5" class="data row2 col5" >48.32</td>
      <td id="T_45521_row2_col6" class="data row2 col6" >50</td>
      <td id="T_45521_row2_col7" class="data row2 col7" >96.64</td>
      <td id="T_45521_row2_col8" class="data row2 col8" >86</td>
      <td id="T_45521_row2_col9" class="data row2 col9" >11</td>
      <td id="T_45521_row2_col10" class="data row2 col10" >3</td>
      <td id="T_45521_row2_col11" class="data row2 col11" >13.96</td>
    </tr>
    <tr>
      <td id="T_45521_row3_col0" class="data row3 col0" >14-Dec-2021</td>
      <td id="T_45521_row3_col1" class="data row3 col1" >PNUV</td>
      <td id="T_45521_row3_col2" class="data row3 col2" >PNUV</td>
      <td id="T_45521_row3_col3" class="data row3 col3" >3</td>
      <td id="T_45521_row3_col4" class="data row3 col4" >9</td>
      <td id="T_45521_row3_col5" class="data row3 col5" >32.45</td>
      <td id="T_45521_row3_col6" class="data row3 col6" >0</td>
      <td id="T_45521_row3_col7" class="data row3 col7" >0.00</td>
      <td id="T_45521_row3_col8" class="data row3 col8" >100</td>
      <td id="T_45521_row3_col9" class="data row3 col9" >0</td>
      <td id="T_45521_row3_col10" class="data row3 col10" >0</td>
      <td id="T_45521_row3_col11" class="data row3 col11" >0.00</td>
    </tr>
    <tr>
      <td id="T_45521_row4_col0" class="data row4 col0" >14-Dec-2021</td>
      <td id="T_45521_row4_col1" class="data row4 col1" >Par Fund</td>
      <td id="T_45521_row4_col2" class="data row4 col2" >PPXX</td>
      <td id="T_45521_row4_col3" class="data row4 col3" >7595</td>
      <td id="T_45521_row4_col4" class="data row4 col4" >51493</td>
      <td id="T_45521_row4_col5" class="data row4 col5" >14.75</td>
      <td id="T_45521_row4_col6" class="data row4 col6" >15</td>
      <td id="T_45521_row4_col7" class="data row4 col7" >98.34</td>
      <td id="T_45521_row4_col8" class="data row4 col8" >78</td>
      <td id="T_45521_row4_col9" class="data row4 col9" >13</td>
      <td id="T_45521_row4_col10" class="data row4 col10" >4</td>
      <td id="T_45521_row4_col11" class="data row4 col11" >16.85</td>
    </tr>
    <tr>
      <td id="T_45521_row5_col0" class="data row5 col0" >14-Dec-2021</td>
      <td id="T_45521_row5_col1" class="data row5 col1" >Share Holders Fund</td>
      <td id="T_45521_row5_col2" class="data row5 col2" >SXXX</td>
      <td id="T_45521_row5_col3" class="data row5 col3" >27</td>
      <td id="T_45521_row5_col4" class="data row5 col4" >3258</td>
      <td id="T_45521_row5_col5" class="data row5 col5" >0.83</td>
      <td id="T_45521_row5_col6" class="data row5 col6" >0</td>
      <td id="T_45521_row5_col7" class="data row5 col7" >0.00</td>
      <td id="T_45521_row5_col8" class="data row5 col8" >0</td>
      <td id="T_45521_row5_col9" class="data row5 col9" >76</td>
      <td id="T_45521_row5_col10" class="data row5 col10" >24</td>
      <td id="T_45521_row5_col11" class="data row5 col11" >100.00</td>
    </tr>
    <tr>
      <td id="T_45521_row6_col0" class="data row6 col0" >14-Dec-2021</td>
      <td id="T_45521_row6_col1" class="data row6 col1" >Life Balanced Fund</td>
      <td id="T_45521_row6_col2" class="data row6 col2" >UEBAL</td>
      <td id="T_45521_row6_col3" class="data row6 col3" >1159</td>
      <td id="T_45521_row6_col4" class="data row6 col4" >3453</td>
      <td id="T_45521_row6_col5" class="data row6 col5" >33.55</td>
      <td id="T_45521_row6_col6" class="data row6 col6" >30</td>
      <td id="T_45521_row6_col7" class="data row6 col7" >111.84</td>
      <td id="T_45521_row6_col8" class="data row6 col8" >73</td>
      <td id="T_45521_row6_col9" class="data row6 col9" >18</td>
      <td id="T_45521_row6_col10" class="data row6 col10" >8</td>
      <td id="T_45521_row6_col11" class="data row6 col11" >26.61</td>
    </tr>
    <tr>
      <td id="T_45521_row7_col0" class="data row7 col0" >14-Dec-2021</td>
      <td id="T_45521_row7_col1" class="data row7 col1" >Life Conservative Fund</td>
      <td id="T_45521_row7_col2" class="data row7 col2" >UECON</td>
      <td id="T_45521_row7_col3" class="data row7 col3" >26</td>
      <td id="T_45521_row7_col4" class="data row7 col4" >260</td>
      <td id="T_45521_row7_col5" class="data row7 col5" >9.82</td>
      <td id="T_45521_row7_col6" class="data row7 col6" >10</td>
      <td id="T_45521_row7_col7" class="data row7 col7" >98.15</td>
      <td id="T_45521_row7_col8" class="data row7 col8" >85</td>
      <td id="T_45521_row7_col9" class="data row7 col9" >12</td>
      <td id="T_45521_row7_col10" class="data row7 col10" >3</td>
      <td id="T_45521_row7_col11" class="data row7 col11" >15.27</td>
    </tr>
    <tr>
      <td id="T_45521_row8_col0" class="data row8 col0" >14-Dec-2021</td>
      <td id="T_45521_row8_col1" class="data row8 col1" >Diversified Equity Fund</td>
      <td id="T_45521_row8_col2" class="data row8 col2" >UEDE1</td>
      <td id="T_45521_row8_col3" class="data row8 col3" >584</td>
      <td id="T_45521_row8_col4" class="data row8 col4" >602</td>
      <td id="T_45521_row8_col5" class="data row8 col5" >96.95</td>
      <td id="T_45521_row8_col6" class="data row8 col6" >100</td>
      <td id="T_45521_row8_col7" class="data row8 col7" >96.95</td>
      <td id="T_45521_row8_col8" class="data row8 col8" >71</td>
      <td id="T_45521_row8_col9" class="data row8 col9" >24</td>
      <td id="T_45521_row8_col10" class="data row8 col10" >5</td>
      <td id="T_45521_row8_col11" class="data row8 col11" >29.48</td>
    </tr>
    <tr>
      <td id="T_45521_row9_col0" class="data row9 col0" >14-Dec-2021</td>
      <td id="T_45521_row9_col1" class="data row9 col1" >Dynamic Opportunity Fund</td>
      <td id="T_45521_row9_col2" class="data row9 col2" >UEDO1</td>
      <td id="T_45521_row9_col3" class="data row9 col3" >309</td>
      <td id="T_45521_row9_col4" class="data row9 col4" >607</td>
      <td id="T_45521_row9_col5" class="data row9 col5" >50.87</td>
      <td id="T_45521_row9_col6" class="data row9 col6" >50</td>
      <td id="T_45521_row9_col7" class="data row9 col7" >101.74</td>
      <td id="T_45521_row9_col8" class="data row9 col8" >82</td>
      <td id="T_45521_row9_col9" class="data row9 col9" >13</td>
      <td id="T_45521_row9_col10" class="data row9 col10" >6</td>
      <td id="T_45521_row9_col11" class="data row9 col11" >18.11</td>
    </tr>
    <tr>
      <td id="T_45521_row10_col0" class="data row10 col0" >14-Dec-2021</td>
      <td id="T_45521_row10_col1" class="data row10 col1" >Amsure Dynamic Fund</td>
      <td id="T_45521_row10_col2" class="data row10 col2" >UEGFD</td>
      <td id="T_45521_row10_col3" class="data row10 col3" >1</td>
      <td id="T_45521_row10_col4" class="data row10 col4" >5</td>
      <td id="T_45521_row10_col5" class="data row10 col5" >14.37</td>
      <td id="T_45521_row10_col6" class="data row10 col6" >15</td>
      <td id="T_45521_row10_col7" class="data row10 col7" >95.81</td>
      <td id="T_45521_row10_col8" class="data row10 col8" >85</td>
      <td id="T_45521_row10_col9" class="data row10 col9" >11</td>
      <td id="T_45521_row10_col10" class="data row10 col10" >3</td>
      <td id="T_45521_row10_col11" class="data row10 col11" >14.53</td>
    </tr>
    <tr>
      <td id="T_45521_row11_col0" class="data row11 col0" >14-Dec-2021</td>
      <td id="T_45521_row11_col1" class="data row11 col1" >Amsure Income Fund</td>
      <td id="T_45521_row11_col2" class="data row11 col2" >UEGFI</td>
      <td id="T_45521_row11_col3" class="data row11 col3" >0</td>
      <td id="T_45521_row11_col4" class="data row11 col4" >1</td>
      <td id="T_45521_row11_col5" class="data row11 col5" >4.28</td>
      <td id="T_45521_row11_col6" class="data row11 col6" >5</td>
      <td id="T_45521_row11_col7" class="data row11 col7" >85.68</td>
      <td id="T_45521_row11_col8" class="data row11 col8" >88</td>
      <td id="T_45521_row11_col9" class="data row11 col9" >9</td>
      <td id="T_45521_row11_col10" class="data row11 col10" >3</td>
      <td id="T_45521_row11_col11" class="data row11 col11" >11.94</td>
    </tr>
    <tr>
      <td id="T_45521_row12_col0" class="data row12 col0" >14-Dec-2021</td>
      <td id="T_45521_row12_col1" class="data row12 col1" >Life Growth Fund</td>
      <td id="T_45521_row12_col2" class="data row12 col2" >UEGRW</td>
      <td id="T_45521_row12_col3" class="data row12 col3" >4480</td>
      <td id="T_45521_row12_col4" class="data row12 col4" >8708</td>
      <td id="T_45521_row12_col5" class="data row12 col5" >51.45</td>
      <td id="T_45521_row12_col6" class="data row12 col6" >50</td>
      <td id="T_45521_row12_col7" class="data row12 col7" >102.90</td>
      <td id="T_45521_row12_col8" class="data row12 col8" >86</td>
      <td id="T_45521_row12_col9" class="data row12 col9" >11</td>
      <td id="T_45521_row12_col10" class="data row12 col10" >3</td>
      <td id="T_45521_row12_col11" class="data row12 col11" >13.51</td>
    </tr>
    <tr>
      <td id="T_45521_row13_col0" class="data row13 col0" >14-Dec-2021</td>
      <td id="T_45521_row13_col1" class="data row13 col1" >High Growth Fund</td>
      <td id="T_45521_row13_col2" class="data row13 col2" >UEHGW</td>
      <td id="T_45521_row13_col3" class="data row13 col3" >1325</td>
      <td id="T_45521_row13_col4" class="data row13 col4" >1356</td>
      <td id="T_45521_row13_col5" class="data row13 col5" >97.74</td>
      <td id="T_45521_row13_col6" class="data row13 col6" >100</td>
      <td id="T_45521_row13_col7" class="data row13 col7" >97.74</td>
      <td id="T_45521_row13_col8" class="data row13 col8" >18</td>
      <td id="T_45521_row13_col9" class="data row13 col9" >66</td>
      <td id="T_45521_row13_col10" class="data row13 col10" >17</td>
      <td id="T_45521_row13_col11" class="data row13 col11" >82.26</td>
    </tr>
    <tr>
      <td id="T_45521_row14_col0" class="data row14 col0" >14-Dec-2021</td>
      <td id="T_45521_row14_col1" class="data row14 col1" >Growth Super</td>
      <td id="T_45521_row14_col2" class="data row14 col2" >UEPEQ</td>
      <td id="T_45521_row14_col3" class="data row14 col3" >9834</td>
      <td id="T_45521_row14_col4" class="data row14 col4" >10086</td>
      <td id="T_45521_row14_col5" class="data row14 col5" >97.50</td>
      <td id="T_45521_row14_col6" class="data row14 col6" >100</td>
      <td id="T_45521_row14_col7" class="data row14 col7" >97.50</td>
      <td id="T_45521_row14_col8" class="data row14 col8" >90</td>
      <td id="T_45521_row14_col9" class="data row14 col9" >8</td>
      <td id="T_45521_row14_col10" class="data row14 col10" >2</td>
      <td id="T_45521_row14_col11" class="data row14 col11" >10.37</td>
    </tr>
    <tr>
      <td id="T_45521_row15_col0" class="data row15 col0" >14-Dec-2021</td>
      <td id="T_45521_row15_col1" class="data row15 col1" >Pension Preserver Fund</td>
      <td id="T_45521_row15_col2" class="data row15 col2" >UEPWA</td>
      <td id="T_45521_row15_col3" class="data row15 col3" >46</td>
      <td id="T_45521_row15_col4" class="data row15 col4" >286</td>
      <td id="T_45521_row15_col5" class="data row15 col5" >16.03</td>
      <td id="T_45521_row15_col6" class="data row15 col6" >15</td>
      <td id="T_45521_row15_col7" class="data row15 col7" >106.86</td>
      <td id="T_45521_row15_col8" class="data row15 col8" >75</td>
      <td id="T_45521_row15_col9" class="data row15 col9" >18</td>
      <td id="T_45521_row15_col10" class="data row15 col10" >6</td>
      <td id="T_45521_row15_col11" class="data row15 col11" >24.58</td>
    </tr>
    <tr>
      <td id="T_45521_row16_col0" class="data row16 col0" >14-Dec-2021</td>
      <td id="T_45521_row16_col1" class="data row16 col1" >Pension Maximiser Fund</td>
      <td id="T_45521_row16_col2" class="data row16 col2" >UEPWC</td>
      <td id="T_45521_row16_col3" class="data row16 col3" >358</td>
      <td id="T_45521_row16_col4" class="data row16 col4" >744</td>
      <td id="T_45521_row16_col5" class="data row16 col5" >48.08</td>
      <td id="T_45521_row16_col6" class="data row16 col6" >50</td>
      <td id="T_45521_row16_col7" class="data row16 col7" >96.16</td>
      <td id="T_45521_row16_col8" class="data row16 col8" >74</td>
      <td id="T_45521_row16_col9" class="data row16 col9" >21</td>
      <td id="T_45521_row16_col10" class="data row16 col10" >5</td>
      <td id="T_45521_row16_col11" class="data row16 col11" >25.94</td>
    </tr>
    <tr>
      <td id="T_45521_row17_col0" class="data row17 col0" >14-Dec-2021</td>
      <td id="T_45521_row17_col1" class="data row17 col1" >Pension Balanced Fund</td>
      <td id="T_45521_row17_col2" class="data row17 col2" >UPBAL</td>
      <td id="T_45521_row17_col3" class="data row17 col3" >33</td>
      <td id="T_45521_row17_col4" class="data row17 col4" >89</td>
      <td id="T_45521_row17_col5" class="data row17 col5" >36.66</td>
      <td id="T_45521_row17_col6" class="data row17 col6" >30</td>
      <td id="T_45521_row17_col7" class="data row17 col7" >122.21</td>
      <td id="T_45521_row17_col8" class="data row17 col8" >72</td>
      <td id="T_45521_row17_col9" class="data row17 col9" >21</td>
      <td id="T_45521_row17_col10" class="data row17 col10" >7</td>
      <td id="T_45521_row17_col11" class="data row17 col11" >28.32</td>
    </tr>
    <tr>
      <td id="T_45521_row18_col0" class="data row18 col0" >14-Dec-2021</td>
      <td id="T_45521_row18_col1" class="data row18 col1" >Pension Conservative Fund</td>
      <td id="T_45521_row18_col2" class="data row18 col2" >UPCON</td>
      <td id="T_45521_row18_col3" class="data row18 col3" >1</td>
      <td id="T_45521_row18_col4" class="data row18 col4" >9</td>
      <td id="T_45521_row18_col5" class="data row18 col5" >9.66</td>
      <td id="T_45521_row18_col6" class="data row18 col6" >10</td>
      <td id="T_45521_row18_col7" class="data row18 col7" >96.59</td>
      <td id="T_45521_row18_col8" class="data row18 col8" >86</td>
      <td id="T_45521_row18_col9" class="data row18 col9" >11</td>
      <td id="T_45521_row18_col10" class="data row18 col10" >3</td>
      <td id="T_45521_row18_col11" class="data row18 col11" >14.42</td>
    </tr>
    <tr>
      <td id="T_45521_row19_col0" class="data row19 col0" >14-Dec-2021</td>
      <td id="T_45521_row19_col1" class="data row19 col1" >Pension Growth Fund</td>
      <td id="T_45521_row19_col2" class="data row19 col2" >UPGRW</td>
      <td id="T_45521_row19_col3" class="data row19 col3" >197</td>
      <td id="T_45521_row19_col4" class="data row19 col4" >370</td>
      <td id="T_45521_row19_col5" class="data row19 col5" >53.15</td>
      <td id="T_45521_row19_col6" class="data row19 col6" >50</td>
      <td id="T_45521_row19_col7" class="data row19 col7" >106.31</td>
      <td id="T_45521_row19_col8" class="data row19 col8" >82</td>
      <td id="T_45521_row19_col9" class="data row19 col9" >13</td>
      <td id="T_45521_row19_col10" class="data row19 col10" >5</td>
      <td id="T_45521_row19_col11" class="data row19 col11" >17.52</td>
    </tr>
    <tr>
      <td id="T_45521_row20_col0" class="data row20 col0" >14-Dec-2021</td>
      <td id="T_45521_row20_col1" class="data row20 col1" >Pension Growth Super</td>
      <td id="T_45521_row20_col2" class="data row20 col2" >UPPEQ</td>
      <td id="T_45521_row20_col3" class="data row20 col3" >299</td>
      <td id="T_45521_row20_col4" class="data row20 col4" >301</td>
      <td id="T_45521_row20_col5" class="data row20 col5" >99.13</td>
      <td id="T_45521_row20_col6" class="data row20 col6" >100</td>
      <td id="T_45521_row20_col7" class="data row20 col7" >99.13</td>
      <td id="T_45521_row20_col8" class="data row20 col8" >76</td>
      <td id="T_45521_row20_col9" class="data row20 col9" >20</td>
      <td id="T_45521_row20_col10" class="data row20 col10" >4</td>
      <td id="T_45521_row20_col11" class="data row20 col11" >24.25</td>
    </tr>
  </tbody>
</table>

此文件在浏览器中打开时会正确显示所有要求的格式。

然而,当我尝试将 html 文件附加到 outlook 电子邮件正文时,收到邮件时格式全部丢失

下面是读取 html 并附加到 outlook 和发送电子邮件的代码。

mail = outlook.CreateItem(0)
mail.To = toaddress
mail.Subject = mailsubject
mail.BodyFormat=3
mail.Display()

inspector = outlook.ActiveInspector()
word_editor = inspector.WordEditor

report_file = open(emailbodyfile,encoding='utf8')
html = report_file.read()

mail.HTMLBody =  html# doc.Content


mail.Send()
print('email sent')

以上html内容取自变量引用的文件:emailbodyfile 这里有什么问题?

我有另一个生成 html 输出的代码(win32com 用于将 excel 保存为 html 并格式化)工作正常

是否与dataframe.to_html()

生成的html有关

首先,确保将 HTMLBody 属性 设置为格式正确的 HTML 字符串。尝试分配格式错误的 HTML 字符串可能会以空白正文结束。

请注意,Outlook 使用 Word 作为邮件正文的编辑器。因此,它应用自己的规则 HTML 标记。在 Word HTML and CSS Rendering Capabilities in Outlook 文章中阅读更多相关信息。

已解决:

'border-spacing': '10px 50px'; 

样式部分中的上一行引起了问题:(