I use Spire.Office to convert gridview data to PDF. I got data in .pdf file but not in the correct format so I try this code:
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<html>");
sb.AppendFormat("<body>");
sb.AppendFormat("<table>");
sb.AppendFormat("<tr>");
foreach (DataGridViewColumn column in dgv.Columns)
{
sb.AppendFormat("<th>");
sb.AppendFormat(column.Name);
sb.AppendFormat("</th>");
}
sb.AppendFormat("</tr>");
sb.AppendFormat("<tr>");
foreach (DataGridViewRow row in dgv.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
sb.AppendFormat("<td>");
sb.Append(cell.Value);
sb.AppendFormat("</td>");
}
}
sb.AppendFormat("</tr>");
sb.AppendFormat("</table>");
sb.AppendFormat("</body>");
sb.Append("</html>");
return sb.ToString();
I got output data with tags.