SHARE
TWEET

Create Word Doc In PHP

sunlitlaz Apr 14th, 2012 833 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   $o = "Whatever content I want IN the document!";
  2.   $fp = fopen("myfile.doc", 'w+');
  3.   $hdr = "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"\n
  4. xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n
  5. xmlns:w=\"urn:schemas-microsoft-com:office:word\"\n
  6. xmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\"\n
  7. xmlns=\"http://www.w3.org/TR/REC-html40\">\n\n
  8.  
  9. <head>
  10.  
  11. <meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n
  12. <meta name=ProgId content=Word.Document>\n
  13. <meta name=Generator content=\"Microsoft Word 12\">\n
  14. <meta name=Originator content=\"Microsoft Word 12\">\n
  15. <style>
  16. <!--
  17. /* Font Definitions */
  18. @font-face
  19.  {font-family:\"MS Mincho\";
  20.  panose-1:2 2 6 9 4 2 5 8 3 4;
  21.  mso-font-alt:\"\FF2D\FF33 \660E\671D\";
  22.  mso-font-charset:128;
  23.  mso-generic-font-family:modern;
  24.  mso-font-pitch:fixed;
  25.  mso-font-signature:-1610612033 1757936891 16 0 131231 0;}
  26. @font-face
  27.  {font-family:\"Cambria Math\";
  28.  panose-1:2 4 5 3 5 4 6 3 2 4;
  29.  mso-font-charset:1;
  30.  mso-generic-font-family:roman;
  31.  mso-font-format:other;
  32.  mso-font-pitch:variable;
  33.  mso-font-signature:0 0 0 0 0 0;}
  34. @font-face
  35.  {font-family:Calibri;
  36.  panose-1:2 15 5 2 2 2 4 3 2 4;
  37.  mso-font-charset:0;
  38.  mso-generic-font-family:roman;
  39.  mso-font-pitch:variable;
  40.  mso-font-signature:-1610611985 1073750139 0 0 159 0;}
  41. @font-face
  42.  {font-family:\"\@MS Mincho\";
  43.  mso-font-charset:128;
  44.  mso-generic-font-family:modern;
  45.  mso-font-pitch:fixed;
  46.  mso-font-signature:-1610612033 1757936891 16 0 131231 0;}
  47. /* Style Definitions */
  48. p.MsoNormal, li.MsoNormal, div.MsoNormal
  49.  {mso-style-unhide:no;
  50.  mso-style-qformat:yes;
  51.  mso-style-parent:\"\";
  52.  margin-top:0in;
  53.  margin-right:0in;
  54.  margin-bottom:10.0pt;
  55.  margin-left:0in;
  56.  line-height:115%;
  57.  mso-pagination:widow-orphan;
  58.  font-size:11.0pt;
  59.  font-family:\"Calibri\",\"serif\";
  60.  mso-ascii-font-family:Calibri;
  61.  mso-ascii-theme-font:minor-latin;
  62.  mso-fareast-font-family:\"MS Mincho\";
  63.  mso-fareast-theme-font:minor-fareast;
  64.  mso-hansi-font-family:Calibri;
  65.  mso-hansi-theme-font:minor-latin;
  66.  mso-bidi-font-family:Arial;
  67.  mso-bidi-theme-font:minor-bidi;}
  68. .MsoChpDefault
  69.  {mso-style-type:export-only;
  70.  mso-default-props:yes;
  71.  mso-ascii-font-family:Calibri;
  72.  mso-ascii-theme-font:minor-latin;
  73.  mso-fareast-font-family:\"MS Mincho\";
  74.  mso-fareast-theme-font:minor-fareast;
  75.  mso-hansi-font-family:Calibri;
  76.  mso-hansi-theme-font:minor-latin;
  77.  mso-bidi-font-family:Arial;
  78.  mso-bidi-theme-font:minor-bidi;}
  79. .MsoPapDefault
  80.  {mso-style-type:export-only;
  81.  margin-bottom:10.0pt;
  82.  line-height:115%;}
  83. @page Section1
  84.  {size:8.5in 11.0in;
  85.  margin:1.0in 1.0in 1.0in 1.0in;
  86.  mso-header-margin:.5in;
  87.  mso-footer-margin:.5in;
  88.  mso-paper-source:0;}
  89. div.Section1
  90.  {page:Section1;}
  91. -->
  92. </style>\n</head>
  93. <body lang=EN-US style='tab-interval:.5in'>
  94. <div class=Section1>";
  95.  
  96.   fwrite($fp, $hdr);
  97.   fwrite($fp, $o);
  98.   fclose($fp);
  99.   header("Content-Type: application/vnd.ms-word");
  100.   header("Expires: 0");
  101.   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  102.   header("content-disposition: attachment;filename=myfile.doc");
  103.   header("location: myfile.doc");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top