convert HTML to word format

10.5k views Asked by At

I use word automation to create a word document. I want to embed some html code in that file. how should I cnvert html tags to word document format? ( I want to keep font, bold, table and other styles in html)

1

There are 1 answers

8
Akshay Randive On BEST ANSWER
 HttpContext.Current.Response.Clear();  
 HttpContext.Current.Response.Charset = "";  
 HttpContext.Current.Response.ContentType = "application/msword";  
 string strFileName = "docName" + ".doc";  
 HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);  

 StringBuilder strHTMLContent = new StringBuilder();  
 strHTMLContent.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:word\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head></head><body>");
 strHTMLContent.Append(htmlContent); 
 strHTMLContent.Append("</body></html>");    

 HttpContext.Current.Response.Write(strHTMLContent);  
 HttpContext.Current.Response.End();  
 HttpContext.Current.Response.Flush();