c# - StringBuilder 的 AppendFormat 方法创建 Table

标签 c# asp.net

我对 StringBuilder 类的 AppendFormat 方法有疑问。 我正在创建表格并在字符串生成器对象中附加数据以将其作为邮件发送,但是当我看到我发送的邮件时,它看起来不像表格,它的标题和相应的内容都错放了。我希望表格用行分隔,因为它通常在 Microsoft Word 的表格中。 我怎样才能实现它.. 我正在使用以下代码:Body 是一个 StringBuilder 对象

if (  dic1 != null )
{
     //Body.AppendFormat("Client: " + cl + " Success. " + dic1.Count + " :");
     Body.AppendFormat("<br/><table>");
     Body.AppendFormat("<h1><tr><td>#</td><td>Files Name</td></tr></h1>");
     int count = 1;
      foreach ((KeyValuePair<string, string> pair in  dic1)
               {
                    if (!String.IsNullOrEmpty(pair.Key))
                     {

                      Body.AppendFormat("<tr><td>"+count.ToString()+"</td><td>" + pair.Key + "</td><td> " + pair.Value + "</td></tr>");
                        count++;
                        //Body.Append( );
                    }
                }

                Body.AppendFormat("</table>");

以下是我在收件箱中收到的输出。

 # File Name Error 
 1 txt1.txt Loading File 'txt1.txt' failed: The specified File already exists in the system 
 2 txt2.txt Loading File 'txt2.txt' failed: The specified File already exists in the system 
 3 txt3.txt Loading File 'txt3.txt' failed: The specified File already exists in the system 

最佳答案

希望你能通过这个例子来理解它应该是怎样的。 如果没有,请告诉我。会帮助你。

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

sb.Append("<table>");
sb.AppendFormat("<tr><td>Request Name:</td><td>{0}</td></tr>", txtBugName.Text.Trim());
sb.AppendFormat("<tr><td>Category:</td><td>{0}</td></tr>", ddlModule.SelectedValue);
sb.AppendFormat("<tr><td>Sub-Category:</td><td>{0}</td></tr>", ddlPage.SelectedValue);
sb.AppendFormat("<tr><td>Description:</td><td>{0}</td></tr>", txtComments.Text.Trim());
sb.AppendFormat("<tr><td>Email is:</td><td>{0}</td></tr>", txtemail.Text.Trim());
sb.Append("<table>");

然后我假设 IsBodyHtml 属性为真,因为您已经在使用 HTML

关于c# - StringBuilder 的 AppendFormat 方法创建 Table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12350015/

相关文章:

c# - 使用 OpenXML 从 Excel 中删除公式

c# - 尝试在不调用 parent 事件的情况下调用 child 的事件

asp.net - ASP MVC href 到 Controller / View

asp.net - 如何使调试 ASP.NET Sharepoint 应用程序的过程更耗时?

asp.net - 结合CLR类库发布ASP.NET vNext/DNX

c# - 如何获取 WPF 应用程序的发布版本

c# - 当我单击 CheckBox 时,Wpf PasswordBox 必须显示字符

c# - 在 Entity Framework 6中调用标量值函数

asp.net - 使用 asp.net core visual studio react 模板部署 Next JS 项目

asp.net - 不了解 IIS 经典模式和集成模式?