Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET CSS HTML PHP Word
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 9-Dec-11 1:53am
Edited 9-Dec-11 1:57am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Answering to my question: Yes, it's possible adapt ASP code to PHP.
 
<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>
 
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.
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 9 Dec 2011
Copyright © CodeProject, 1999-2014
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