PHP Export to Word

$content = “This is test page”;

// Size – Denotes A4, Legal, A3, etc ——- size:8.5in 11.0in; for Legal size
// Margin – Set the margin of the word document – margin:0.5in 0.31in 0.42in 0.25in; [margin: top right bottom left]

$word_xmlns = “xmlns:o=’urn:schemas-microsoft-com:office:office’ xmlns:w=’urn:schemas-microsoft-com:office:word’ xmlns=’′&#8221;;
$word_xml_settings = “<xml><w:WordDocument><w:View>Print</w:View><w:Zoom>100</w:Zoom></w:WordDocument></xml>”;
$word_landscape_style = “@page {size:8.5in 11.0in; margin:0.5in 0.31in 0.42in 0.25in;} div.Section1{page:Section1;}”;
$word_landscape_div_start = “<div class=’Section1′>”;
$word_landscape_div_end = “</div>”;
$content =
<html ‘.$word_xmlns.’>
<head>‘.$word_xml_settings.’<style type=“text/css”>
‘.$word_landscape_style.’ table,td {border:0px solid #FFFFFF;} </style>

@header(‘Content-Type: application/msword’);
@header(‘Content-Length: ‘.strlen($content));
@header(‘Content-disposition: inline; filename=”testdocument.doc”‘);
echo $content;


Thanks to


About selvam4win

I am Selvam. I am very jolly person and frank one.

Posted on December 23, 2010, in Export to Word, PHP, PHP Export, Word and tagged , . Bookmark the permalink. 7 Comments.

  1. thank you all, but I face one problem….
    the content contains both Big5 and GB code, when I try to download as a word file, those GB code can’t display properly, how can I fix it?

  1. Pingback: NEW | Wordpress Demo

  2. Pingback: PHP Export ke Excel dan Word « Mahrizal

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: