Click here to Skip to main content
13,140,231 members (47,699 online)
Rate this:
Please Sign up or sign in to vote.
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,

Posted 9-Dec-11 0:53am
Updated 9-Dec-11 0:57am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Take a look at the following discussion:[^]

Same query is discussed in detail.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 9 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100