2
我嘗試使用下面的代碼數據表作爲郵件在C#控制檯應用程序
public static string getHtml(DataTable dataSet)
{
try
{
string messageBody = "<font>The following are the records: </font><br><br>";
if (dataSet.Rows.Count == 0)
return messageBody;
string htmlTableStart = "<table style=\"float:left; border-collapse:collapse; text-align:center;\" >";
string htmlTableEnd = "</table>";
string htmlHeaderRowStart = "<tr style =\"background-color:#6FA1D2; color:#ffffff;\">";
string htmlHeaderRowEnd = "</tr>";
string htmlTrStart = "<tr style =\"color:#555555;\">";
string htmlTrEnd = "</tr>";
string htmlTdStart = "<td style=\" border-color:#5c87b2; border-style:solid; border-width:thin; padding: 5px;\">";
string htmlTdEnd = "</td>";
foreach (DataColumn dc in dataSet.Columns)
{
messageBody += htmlTableStart;
messageBody += htmlHeaderRowStart;
messageBody += htmlTdStart + dc + htmlTdEnd;
messageBody += htmlHeaderRowEnd;
foreach (DataRow Row in dataSet.Rows)
{
messageBody = messageBody + htmlTrStart;
messageBody = messageBody + htmlTdStart + Row["" + dc + ""] + htmlTdEnd;
messageBody = messageBody + htmlTrEnd;
}
}
messageBody = messageBody + htmlTableEnd;
return messageBody;
}
catch (Exception ex)
{
return null;
}
}
我想要的方式, 所有不同的表應該進來使創建從我的數據集的html水平。我試圖浮動:左但是當我使用這個網站在郵件被髮送,浮動左不工作
能否東西代碼進行更改,以便表進來hozizontally作爲
是否要爲數據庫中的每一行添加新表? – sylwester
試着給表格一個「寬度」。 'style = \「... width:600px ... \」' –
請使用StringBuilder! – DaniCE