Answer the question
In order to leave comments, you need to log in
How to save dataGridView table to html file, in C#?
Please help, at least with an example or material on this topic.
Answer the question
In order to leave comments, you need to log in
private StringBuilder DataGridtoHTML(DataGridView dg)
{
StringBuilder strB = new StringBuilder();
strB.AppendLine("<html><body><center><" +
"table border='1' cellpadding='0' cellspacing='0'>");
strB.AppendLine("<tr>");
for (int i = 0; i < dg.Columns.Count; i++)
{
strB.AppendLine("<td align='center' valign='middle'>" +
dg.Columns[i].HeaderText + "</td>");
}
strB.AppendLine("<tr>");
for (int i = 0; i < dg.Rows.Count; i++)
{
strB.AppendLine("<tr>");
foreach (DataGridViewCell dgvc in dg.Rows[i].Cells)
{
strB.AppendLine("<td align='center' valign='middle'>" +
dgvc.Value.ToString() + "</td>");
}
strB.AppendLine("</tr>");
}
strB.AppendLine("</table></center></body></html>");
return strB;}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question