Click here to Skip to main content
15,350,151 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,

Updated 9-Dec-11 0:57am

Take a look at the following discussion:[^]

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

        <w:worddocument xmlns:w="#unknown">
            <w:donotoptimizeforbrowser />
        @page Section1
        {size:8.5in 11.0in;
         margin:1.0in 1.25in 1.0in 1.25in ;
         mso-footer-margin:.5in; mso-paper-source:0;}
<body lang=EN-US style='tab-interval:.5in'>
    <div class="Section1">
<h1>Hello Word!</h1>

header("Content-type: application/");
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.

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