如何将数据表中的列链接到HTML导出器 [英] How to give link to a column in datatable to HTML exporter
问题描述
我需要在将数据表导出为HTML时添加列(meetingID)的链接
i添加了用于将Datatable转换为HTML的输出和代码
我的尝试:
public bool ExportToHtml(out string path)
{
DataTable dt = ToDataTable(_ collection,_selectedColumns);
StringBuilder strHTMLBuilder = new StringBuilder();
strHTMLBuilder.Append(< html>);
strHTMLBuilder.Append(< head>);
strHTMLBuilder.Append(< / head>);
strHTMLBuilder.Append(< body>);
strHTMLBuilder.Append(< table border ='1px solid black'cellpadding ='1'cellspacing ='1'bgcolor ='LightYellow'style ='font-family:Garamond; font-size:medium; width = 100%>中);
strHTMLBuilder.Append(< tr width = 100%>);
foreach(dt.Columns中的DataColumn myColumn)
{
strHTMLBuilder.Append(< td style ='font-size:medium; font-weight:bold; width = 100%; padding-right:30px'>);
strHTMLBuilder.Append(myColumn.ColumnName);
strHTMLBuilder.Append(< / td>);
}
strHTMLBuilder.Append(< / tr>);
foreach(dt.Rows中的DataRow myRow)
{
strHTMLBuilder.Append(< tr>);
foreach(dt.Columns中的DataColumn myColumn)
{
strHTMLBuilder.Append(< td>);
strHTMLBuilder.Append(myRow [myColumn.ColumnName] .ToString());
strHTMLBuilder.Append(< / td>);
}
strHTMLBuilder.Append(< / tr>);
}
//关闭标签。
strHTMLBuilder.Append(< / table>);
strHTMLBuilder.Append(< / body>);
strHTMLBuilder.Append(< / html>);
string Htmltext = strHTMLBuilder.ToString();
path = string.Format({0} \\ {1}。{2},_ basepath,_ filename,html);
System.IO.File.WriteAllText(path,Htmltext);
//返回Htmltext;
返回true;
}
< html>< head>< / head>< body>< table border ='1px solid black'cellpadding ='1'cellspacing ='1'bgcolor ='LightYellow'style ='font-family:Garamond;字体大小:介质; width = 100%'>< tr width = 100%>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'>会议ID< / td>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'> Portfolio Manager Name< / td>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'> IVZ会议截止日期GMT< / td>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'> IVZ Meeting CutOff Date Local< / td>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'>本地时间< / td>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'> Issuer Name< / td>< td style ='font-size:medium;字体重量:粗体;宽度= 100%; padding-right:30px'> Ticker< / td>< / tr>< tr>< td> 1190516< / td>< td> Josh Goldstein< / td>< td> 2018 -01-18 16:00:00< / td>< td> 2018-01-18 10:00:00< / td>< td> CST / CDT< / td>< td> Siemens AG< / td>< td> SIE< / td>< / tr>< / table>< / body>< / html>
我建议你在形成如下表格列时在sql查询中添加超链接。
SELECT'< a href ='
+ HyperLink
+'>'
+ TextLink
+'< / a>'
FROM YourTable
< or>
public bool ExportToHtml(out string path)
{
DataTable dt = ToDataTable(_ collection,_selectedColumns);
StringBuilder strHTMLBuilder = new StringBuilder();
strHTMLBuilder.Append(< html>);
strHTMLBuilder.Append(< head>);
strHTMLBuilder.Append(< / head>);
strHTMLBuilder.Append(< body>);
strHTMLBuilder.Append(< table border ='1px solid black'cellpadding ='1'cellspacing ='1'bgcolor ='LightYellow'style ='font-family:Garamond; font-size:medium; width = 100%>中);
strHTMLBuilder.Append(< tr width = 100%>);
foreach(dt.Columns中的DataColumn myColumn)
{
strHTMLBuilder.Append(< td style ='font-size:medium; font-weight:bold; width = 100%; padding-right:30px'>);
strHTMLBuilder.Append(< big>< pre>< a href ='HyperLink'>'myColumn.ColumnName'< / a>) ;
strHTMLBuilder.Append();
}
strHTMLBuilder.Append();
foreach(DataRow myRow in dt.Rows)
{
strHTMLBuilder.Append();
foreach(dt.Columns中的DataColumn myColumn)
{
strHTMLBuilder.Append();
strHTMLBuilder.Append(myRow [myColumn.ColumnName] .ToString());
strHTMLBuilder.Append();
}
strHTMLBuilder.Append();
}
//关闭标签。
strHTMLBuilder.Append();
strHTMLBuilder.Append();
strHTMLBuilder.Append();
string Htmltext = strHTMLBuilder.ToString();
path = string.Format({0} \\ {1}。{ 2},_ basepath,_ filename,html);
System.IO.File.WriteAllText(path,Htmltext);
//返回Htmltext;
返回true;
}
如果此解决方案有帮助,请立即投票。
i need to add the link of column (meetingID) while exporting the datatable to HTML
i added the output and code which iam using for conversion of Datatable to HTML
What I have tried:
public bool ExportToHtml(out string path) { DataTable dt = ToDataTable(_collection,_selectedColumns); StringBuilder strHTMLBuilder = new StringBuilder(); strHTMLBuilder.Append("<html >"); strHTMLBuilder.Append("<head>"); strHTMLBuilder.Append("</head>"); strHTMLBuilder.Append("<body>"); strHTMLBuilder.Append("<table border='1px solid black' cellpadding='1' cellspacing='1' bgcolor='LightYellow' style='font-family:Garamond; font-size:medium; width=100%'>"); strHTMLBuilder.Append("<tr width=100% >"); foreach (DataColumn myColumn in dt.Columns) { strHTMLBuilder.Append("<td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >"); strHTMLBuilder.Append(myColumn.ColumnName); strHTMLBuilder.Append("</td>"); } strHTMLBuilder.Append("</tr>"); foreach (DataRow myRow in dt.Rows) { strHTMLBuilder.Append("<tr >"); foreach (DataColumn myColumn in dt.Columns) { strHTMLBuilder.Append("<td >"); strHTMLBuilder.Append(myRow[myColumn.ColumnName].ToString()); strHTMLBuilder.Append("</td>"); } strHTMLBuilder.Append("</tr>"); } //Close tags. strHTMLBuilder.Append("</table>"); strHTMLBuilder.Append("</body>"); strHTMLBuilder.Append("</html>"); string Htmltext = strHTMLBuilder.ToString(); path = string.Format("{0}\\{1}.{2}", _basepath, _filename, "html"); System.IO.File.WriteAllText(path, Htmltext); //return Htmltext; return true; }
<html ><head></head><body><table border='1px solid black' cellpadding='1' cellspacing='1' bgcolor='LightYellow' style='font-family:Garamond; font-size:medium; width=100%'><tr width=100% ><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >Meeting ID</td><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >Portfolio Manager Name </td><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >IVZ Meeting Cutoff Date GMT</td><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >IVZ Meeting CutOff Date Local</td><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >local time</td><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >Issuer Name</td><td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >Ticker</td></tr><tr ><td >1190516</td><td >Josh Goldstein</td><td >2018-01-18 16:00:00</td><td >2018-01-18 10:00:00</td><td >CST/CDT</td><td >Siemens AG</td><td >SIE</td></tr></table></body></html>
I suggest you to add hyperlinks in sql query itself when you are forming table columns like below.
SELECT '<a href="' + HyperLink + '">' + TextLink + '</a>' FROM YourTable
<or>
public bool ExportToHtml(out string path) { DataTable dt = ToDataTable(_collection,_selectedColumns); StringBuilder strHTMLBuilder = new StringBuilder(); strHTMLBuilder.Append("<html >"); strHTMLBuilder.Append("<head>"); strHTMLBuilder.Append("</head>"); strHTMLBuilder.Append("<body>"); strHTMLBuilder.Append("<table border='1px solid black' cellpadding='1' cellspacing='1' bgcolor='LightYellow' style='font-family:Garamond; font-size:medium; width=100%'>"); strHTMLBuilder.Append("<tr width=100% >"); foreach (DataColumn myColumn in dt.Columns) { strHTMLBuilder.Append("<td style='font-size:medium; font-weight:bold;width=100%; padding-right: 30px' >"); strHTMLBuilder.Append(<big><pre>"<a href='"HyperLink"'>'"myColumn.ColumnName"'</a>");
strHTMLBuilder.Append("");
}
strHTMLBuilder.Append("");
foreach (DataRow myRow in dt.Rows)
{
strHTMLBuilder.Append("");
foreach (DataColumn myColumn in dt.Columns)
{
strHTMLBuilder.Append("");
strHTMLBuilder.Append(myRow[myColumn.ColumnName].ToString());
strHTMLBuilder.Append("");
}
strHTMLBuilder.Append("");
}
//Close tags.
strHTMLBuilder.Append("");
strHTMLBuilder.Append("");
strHTMLBuilder.Append("");
string Htmltext = strHTMLBuilder.ToString();
path = string.Format("{0}\\{1}.{2}", _basepath, _filename, "html");
System.IO.File.WriteAllText(path, Htmltext);
//return Htmltext;
return true;
}
Please up vote if this solution helps.
这篇关于如何将数据表中的列链接到HTML导出器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!