Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everybody!

Yesterday I read the article "Dynamically generate a MS Word document using HTML & CSS" Dynamically generate a MS Word document using HTML & CSS[^] and I really enjoyed read it. But all this code only works on ASP instead PHP. I want develop a small application that can generate a MS word document via PHP.
I tried COM and I didn't like using COM objects and is necessary MS Word installed on server to generate MS Word document. In my opinion, it's not appellative!
I also tried HTTP headers but I didn't like the final product. The layout is Web instead Print, the page is portrait instead landscape.

Is it possible adapt code written in ASP to PHP?
I would appreciate some constructive suggestions to overcome this small obstacle.

Best Regards,

Peter
Posted
Updated 9-Dec-11 0:57am
v2

Take a look at the following discussion:
http://stackoverflow.com/questions/124959/create-word-document-using-php-in-linux[^]

Same query is discussed in detail.
 
Share this answer
 
Answering to my question: Yes, it's possible adapt ASP code to PHP.

HTML
<html
    xmlns:o='urn:schemas-microsoft-com:office:office'
    xmlns:w='urn:schemas-microsoft-com:office:word'
    xmlns='http://www.w3.org/TR/REC-html40'>
    <head><title>Time</title>
    <xml>
        <w:worddocument xmlns:w="#unknown">
            <w:view>Print</w:view>
            <w:zoom>90</w:zoom>
            <w:donotoptimizeforbrowser />
        </w:worddocument>
    </xml>
    <style>
        @page Section1
        {size:8.5in 11.0in;
         margin:1.0in 1.25in 1.0in 1.25in ;
         mso-header-margin:.5in;
         mso-footer-margin:.5in; mso-paper-source:0;}
        div.Section1
        {page:Section1;}
    </style>
</head>
<body lang=EN-US style='tab-interval:.5in'>
    <div class="Section1">
<h1>Hello Word!</h1>
    </div>
</body>
</html>


PHP
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=report_".date("d_m_Y_G_i").".doc");
?>


Your editor PHP, maybe, can alert you about some unknown HTML tag . You must ignore it.

I would like to thanks at 'Anil' Radhakrishna for his contribution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900