Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 0.97 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Django output word files(.doc),only show raw html in the contents
  2. response = HttpResponse(view_data, content_type='application/vnd.ms-word')
  3. response['Content-Disposition'] = 'attachment; filename=file.doc'
  4. return response
  5.        
  6. <h1>some contents</h1>
  7.        
  8. <html>
  9. <head>
  10. <META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=UTF-8"">
  11. <meta name=ProgId content=Word.Document>
  12. <meta name=Generator content=""Microsoft Word 9"">
  13. <meta name=Originator content=""Microsoft Word 9"">
  14. <style>
  15. @page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
  16. div.Section1 {page:Section1;}
  17. @page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
  18. div.Section2 {page:Section2;}
  19. </style>
  20. </head>
  21. <body>
  22. <div class=Section2>
  23. 'Section1: Portrait, Section2: Landscape
  24.  
  25. [your text here]
  26.  
  27. </div>
  28. </body>
  29. </html>