如何将格式应用于电子邮件中的HTML表?

问题描述

我使用SQL查询生成HTML代码。 HTML被插入到电子邮件正文中,该电子邮件正文是从数据库发送的。

作为该电子邮件的一部分,我希望在电子邮件正文中有一个表格。我已经想出了如何用一些基本的HTML代码来做到这一点,但是我正在努力格式化表格。

这是我当前的代码/ HTML电子邮件正文文本:

<font face="Calibri">Order Summary at 12:53<P>
            <table>
                    <thead>
                            <tr>
                            <th align="left">&nbsp Order Code</th>
                            <th align="left">Client Name &nbsp</th>
                            <th align="right">Total Orders &nbsp</th>
                            <th align="right">Orders Shipped &nbsp</th>
                            <th align="right">Exceptions: &nbsp</th>
                            <th align="center">A</th>
                            <th align="center">B</th>
                            <th align="center">C</th>
                            <th align="center">D</th>
                            <th align="center">E</th>
                            <th align="center">F</th>
                            <th align="center">G</th>
                </tr>
                    </thead>
                    <tbody>
                            <tr>
                            <td align="left">&nbsp A133D&nbsp</td>
                            <td align="left">&nbspTesco &nbsp</td>
                            <td align="right"> 3 &nbsp</td>
                            <td align="right"> 0 &nbsp</td>
                            <td align="right"> &nbsp </td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            </tr>
                            <tr>
                            <td align="left">&nbsp A134D&nbsp</td>
                            <td align="left">&nbspAsda &nbsp</td>
                            <td align="right"> 2 &nbsp</td>
                            <td align="right"> 0 &nbsp</td>
                            <td align="right"> &nbsp </td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            </tr>
                            <tr>
                            <td align="left">&nbsp A135D&nbsp</td>
                            <td align="left">&nbspMorrisons &nbsp</td>
                            <td align="right"> 1 &nbsp</td>
                            <td align="right"> 0 &nbsp</td>
                            <td align="right"> &nbsp </td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            <td align="center">&nbsp 0 &nbsp</td>
                            </tr>
                    </tbody>
           </table>

非常基础,但是做得很好。

我想做的就是在桌子上添加一些视觉样式。目前,它在白色背景上显示为黑色字符。

我想在表格的所有单元格周围放置边框,以使其看起来像网格。

我还想给标题行上色以使其看起来不错。

理想情况下,我将能够使前四列的标题具有一种颜色,而其余8列(例外)具有另一种颜色,但是如果这样做非常复杂,则所有具有相同颜色的标题将是非常好的。 / p>

解决方法

在电子邮件的HTML中,您必须使用HTML属性/内联样式。

例如,在表格开头标签上:

<table cellpadding="0" cellspacing="0" border="1" style="border-collapse: collapse; border: 1px solid #55ff99;">

在彩色单元格上:

                            <th align="left" style="color:#ffffff;background-color:#008033">&nbsp Order Code</th>
                            <th align="left" style="color:#ffffff;background-color:#008033">Client Name &nbsp</th>
                            <th align="right" style="color:#ffffff;background-color:#008033">Total Orders &nbsp</th>
                            <th align="right" style="color:#ffffff;background-color:#008033">Orders Shipped &nbsp</th>

取决于您编写SQL的方式(例如存储过程),如果计数

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...