How to format data with HTML tag?

0 votes
asked by about Spire.Office Community Edition
edited by

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.

1 Answer

0 votes
No avatar answered by (329k points)

Based on what I've seen on the official forums for Spire.Office, the developers recommended using a different type of code and a syntax called LoadFromHTML.

They also have recommendations regarding the proper syntax that you can use with your code. Use the following link to access the page where you can see how to implement the API conversion for your files/code.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...