Anil Kumar

Anil Kumar

  • 685
  • 1.2k
  • 129.3k

Convert string into Word doc in C$

May 22 2020 4:41 AM
Hi i am developing a customer agreement form where i have Company logo and name on top and rest details in body with terms and condition,
 
i have created that all sting in with help of string builder and then replace spacific data from database,
now i want to convert ouput string in word file,
 
i have tried following code but after converting logo and word is not proper format.
  1. //build the content for the dynamic Word document  
  2. //in HTML alongwith some Office specific style properties.  
  3. var strBody = new StringBuilder();  
  4. strBody.Append("<html " +  
  5. "xmlns:o='urn:schemas-microsoft-com:office:office' " +  
  6. "xmlns:w='urn:schemas-microsoft-com:office:word'" +  
  7. "xmlns='http://www.w3.org/TR/REC-html40'>" +  
  8. "<head><title>Time</title>");  
  9. //The setting specifies document's view after it is downloaded as Print  
  10. //instead of the default Web Layout  
  11. strBody.Append("<!--[if gte mso 9]>" +  
  12. "<xml>" +  
  13. "<w:WordDocument>" +  
  14. "<w:View>Print</w:View>" +  
  15. "<w:Zoom>90</w:Zoom>" +  
  16. "<w:DoNotOptimizeForBrowser/>" +  
  17. "</w:WordDocument>" +  
  18. "</xml>" +  
  19. "<![endif]-->");  
  20. strBody.Append("<style>" +  
  21. "<!-- /* Style Definitions */" +  
  22. "@page Section1" +  
  23. " {size:8.5in 11.0in; " +  
  24. " margin:1.0in 1.25in 1.0in 1.25in ; " +  
  25. " mso-header-margin:.5in; " +  
  26. " mso-footer-margin:.5in; mso-paper-source:0;}" +  
  27. " div.Section1" +  
  28. " {page:Section1;}" +  
  29. "-->" +  
  30. "</style></head>");  
  31. strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" +  
  32. "<div class=Section1>");  
  33. strBody.Append(HtmlCAF);  
  34. strBody.Append("</div></body></html>");  
  35. //Force this content to be downloaded  
  36. //as a Word document with the name of your choice  
  37. Response.AppendHeader("Content-Type""application/msword");  
  38. Response.AppendHeader("Content-disposition""attachment; filename=" + fileName + "");  
  39. Response.Write(strBody.ToString());  
please help

Answers (2)