PHP generates a Word document in the program and provides a download _php tutorial

Source: Internet
Author: User
In this article, we mainly solve two problems:
1: How to generate HTML content into a Word document in PHP
2:php The problem is not centered when the content in HTML is generated in the Word document, it is displayed by default in Web view.
3:php when you generate HTML content into a Word document, the related styles are incompatible.
Body:
Echo '


Print

';
Echo '

"; Echo."
';
echo "Digital teaching system e-Lesson Draft

Experimental Middle School of subject language schools
';
Ob_start (); Open buffer
Header ("Cache-control:public");
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
if (Strpos ($_server["http_user_agent"], ' MSIE ')) {
Header (' content-disposition:attachment; Filename=test.doc ');
}else if (Strpos ($_server["http_user_agent"], ' Firefox ')} {
Header (' content-disposition:attachment; Filename=test.doc ');
} else {
Header (' content-disposition:attachment; Filename=test.doc ');
}
Header ("Pragma:no-cache");
Header ("expires:0");
Ob_end_flush ();//output all content to the browser
Note: The code section above provides the ability to generate content into a Word document in a PHP program file and provide the download functionality.
For question 2nd, the download to a local Word document opens with the default display by Web view: for example:
Follow the Default Web view display:

If you are displaying in the normal page view, you need to add a line of XML markup to your head (the Blue Code section): Print When you add a Word document that is downloaded to a local after it is opened, it appears as:

For the third problem, there are some style incompatibility issues, such as the underline of the related attributes below the top headline:
We have added the border-bottom:1px solid #545454 in the HTML style (Blue Code section), i.e.:
Workaround is to make changes according to the subscript style recognized by word, namely:
to the fish, rather than grant to the fishing, I put my about this solution style incompatible solution to share with you:
One: Find a web version of the online editor, and then enter a few words in it, and then add an underscore
Second: Then click the View Source button above the editor, you can see that the underlined attribute that you just added is text-decoration:underline, not the style tag in HTML: border-bottom:1px solid #545454 ;
OK, in response to the above related issues here, if you have any questions please put forward, we discuss the solution of Kazakhstan.

Sub

http://www.bkjia.com/phpjc/477948.html www.bkjia.com True http://www.bkjia.com/phpjc/477948.html techarticle This article mainly addresses two questions: 1: How to generate HTML content into a Word document in PHP 2:php the problem is not centered when the content in HTML is generated in the Word document ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.