H
H
Higgs2014-12-05 03:04:41
Programming
Higgs, 2014-12-05 03:04:41

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

1 answer(s)
I
Ivan Filatov, 2014-12-05
@NYMEZIDE

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 question

Ask a Question

731 491 924 answers to any question