Click here to Skip to main content
11,921,898 members (39,724 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 1:53am
Edited 9-Dec-11 1: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
0 OriginalGriff 493
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 243
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web01 | 2.8.151120.1 | Last Updated 9 Dec 2011
Copyright © CodeProject, 1999-2015
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