DataRow 转成HTML表格 - DataRowToHtmlTable
2017-02-26 15:59:50 访问(1441) 赞(0) 踩(0)
/// <summary>
/// DataRow 转成HTML表格 - DataRowToHtmlTable
/// </summary>
/// <param name="dr"></param>
/// <param name="needConvertHTML"></param>
/// <returns></returns>
public static string DataRowToHtmlTable(DataRow dr, bool needConvertHTML)
{
if (dr == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "传入参数:DataRow dr为null。"
);
}
DataTable dt = dr.Table;
if (dt == null)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "值:DataTable dt = dr.Table为null。"
);
}
StringBuilder theResult = new StringBuilder();
theResult.Append(@"<table style=""background-color: #CDCDCD; font-family: 仿宋; width:98%"" align=""center"" border=""0"" cellpadding=""1"" cellspacing=""1"">");
if (needConvertHTML)
{
theResult.Append(@"<tr style=""background-color: #FFFFFF;"">");
foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"<td style=""background-color: #FFFFFF; font-size: 18px; font-weight: bold; font-family: 宋体; line-height: 20pt; vertical-align: middle; line-height: 20pt; text-align: center;"" align=""center"" height=""30px"">");
theResult.Append(StringSlowXFunctions.ConvertHtmlTagPrefix(dc.ColumnName));
theResult.Append("</td>");
}
theResult.Append("</tr>");
theResult.Append(@"<tr style=""background-color: #FFFFFF;"">");
foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"<td style=""background-color: #FFFFFF; font-size: 14px; font-family: 宋体; line-height: 20pt; vertical-align: middle; line-height: 20pt; padding-left: 5px;"" align=""center"" height=""30px"">");
theResult.Append(StringSlowXFunctions.ConvertHtmlTagPrefix(dr[dc.ColumnName].ToString()));
theResult.Append("</td>");
}
theResult.Append("</tr>");
}
else
{
theResult.Append(@"<tr style=""background-color: #FFFFFF;"">");
foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"<td style=""background-color: #FFFFFF; font-size: 18px; font-weight: bold; font-family: 宋体; line-height: 20pt; vertical-align: middle; line-height: 20pt; text-align: center;"" align=""center"" height=""30px"">");
theResult.Append(dc.ColumnName);
theResult.Append("</td>");
}
theResult.Append("</tr>");
theResult.Append(@"<tr style=""background-color: #FFFFFF;"">");
foreach (DataColumn dc in dt.Columns)
{
theResult.Append(@"<td style=""background-color: #FFFFFF; font-size: 14px; font-family: 宋体; line-height: 20pt; vertical-align: middle; line-height: 20pt; padding-left: 5px;"" align=""center"" height=""30px"">");
theResult.Append(dr[dc.ColumnName].ToString());
theResult.Append("</td>");
}
theResult.Append("</tr>");
}
theResult.Append("</table>");
return theResult.ToString();
}
标签:
DataRow 转成HTML表格 - DataRowToHtmlTable 


上一条:
下一条:
相关评论
发表评论