Blueprism - 突出显示电子邮件正文中的集合列

时间:2018-05-25 12:46:07

标签: c# blueprism rpa

我有一份工作,将一个集合传递到电子邮件正文中。我想强调第一栏。目前我的代码正在转换第一行。 我怎么能改变这个?

System.Text.StringBuilder sb = new System.Text.StringBuilder);
if(InData.Rows.Count > 0)
{
sb.Append("Hi There,<br><br>");
sb.Append("Please find the below mentioned Information. <br><br>");
sb.Append("<table style='border:1px solid black; border-collapse: collapse;'>");
sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
foreach (System.Data.DataColumn dc in InData.Columns)
{
   sb.Append("<th style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
   sb.Append(dc.ColumnName);
   sb.Append("</th>");
}
sb.Append("</tr>");

int rowNumber = 1;
foreach (System.Data.DataRow dr in InData.Rows)
{
    if (rowNumber == 1)
    {
   sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px; background-color:yellow;'>");
    }
    else
    {
        sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
    }

  foreach (System.Data.DataColumn dc in InData.Columns)
   {
      sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
      sb.Append(dr[dc.ColumnName].ToString());
      sb.Append("</td>");
   }
   sb.Append("</tr>");
   rowNumber ++;
}
sb.Append("</table><br><br>");
sb.Append("Regards,<br>");
sb.Append("Team QueryBot");
}
outEmailHtmlTable = sb.ToString();

1 个答案:

答案 0 :(得分:1)

该行突出显示背景颜色。理想情况下,它应该是列。在下面的代码中,我删除了该行的background-color:yellow;,并将其添加到将突出显示每行第一列的列。

System.Text.StringBuilder sb = new System.Text.StringBuilder;
if(InData.Rows.Count > 0)
{
sb.Append("Hi There,<br><br>");
sb.Append("Please find the below mentioned Information. <br><br>");
sb.Append("<table style='border:1px solid black; border-collapse: collapse;'>");

sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
foreach (System.Data.DataColumn dc in InData.Columns)
{
   sb.Append("<th style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
   sb.Append(dc.ColumnName);
   sb.Append("</th>");
}
sb.Append("</tr>");

int rowNumber = 1;
foreach (System.Data.DataRow dr in InData.Rows)
{

   sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

int colNumber=1;

  foreach (System.Data.DataColumn dc in InData.Columns)
   {

if(colNumber==1)
{
          sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;background-color:yellow;'>");
}
else
{
          sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

}
          sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
          sb.Append(dr[dc.ColumnName].ToString());
          sb.Append("</td>");
colNumber++;
       }
       sb.Append("</tr>");
       rowNumber ++;
    }
    sb.Append("</table><br><br>");
    sb.Append("Regards,<br>");
    sb.Append("Team QueryBot");
    }
    outEmailHtmlTable = sb.ToString();

希望这能解决您的问题。

以下是我用来验证您的参考的代码段。

 private void button1_Click(object sender, EventArgs e)
    {

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append("Hi There,<br><br>");
        sb.Append("Please find the below mentioned Information. <br><br>");
        sb.Append("<table style='border:1px solid black; border-collapse: collapse;'>");
        sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");

        sb.Append("<th style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
        sb.Append("ID");
        sb.Append("</th>");
        sb.Append("<th style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
        sb.Append("Name");
        sb.Append("</th>");

        sb.Append("</tr>");

        int rowNumber = 1;
        foreach (Employee dr in Employee.GetEmpList())
        {
            if (rowNumber == 1)
            {
                sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
            }
            else
            {
                sb.Append("<tr style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
            }
            int col = 1;
            if (col == 1)
            {
                sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;background-color:yellow;'>");

                sb.Append(dr.Id);
                sb.Append("</td>");
            }
            col++;

            sb.Append("<td style='border:1px solid black; border-collapse: collapse; padding:2px;'>");
            sb.Append(dr.Name);
            sb.Append("</td>");
            sb.Append("</tr>");
            rowNumber++;
        }
        sb.Append("</table><br><br>");
        sb.Append("Regards,<br>");
        sb.Append("Team QueryBot");
        string stoutEmailHtmlTable = sb.ToString();
    }
}

class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }

    public static List<Employee> GetEmpList()
    {
        List<Employee> emp = new List<Employee>();
        emp.Add(new Employee() { Id = 1, Name = "Venkatesh" });
        emp.Add(new Employee() { Id = 2, Name = "Ramesh" });
        return emp;
    }
}

&#13;
&#13;
Hi There,<br><br>Please find the below mentioned Information. <br><br><table style='border:1px solid black; border-collapse: collapse;'><tr style='border:1px solid black; border-collapse: collapse; padding:2px;'><th style='border:1px solid black; border-collapse: collapse; padding:2px;'>ID</th><th style='border:1px solid black; border-collapse: collapse; padding:2px;'>Name</th></tr><tr style='border:1px solid black; border-collapse: collapse; padding:2px;'><td style='border:1px solid black; border-collapse: collapse; padding:2px;background-color:yellow;'>1</td><td style='border:1px solid black; border-collapse: collapse; padding:2px;'>Venkatesh</td></tr><tr style='border:1px solid black; border-collapse: collapse; padding:2px;'><td style='border:1px solid black; border-collapse: collapse; padding:2px;background-color:yellow;'>2</td><td style='border:1px solid black; border-collapse: collapse; padding:2px;'>Ramesh</td></tr></table><br><br>Regards,<br>Team QueryBot
&#13;
&#13;
&#13;

Snap shot of my output in html