PHP generates a Word document in the program and provides the downloaded code _php instance

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:
Copy CodeThe code is as follows:
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 tags to your head (the Blue Code section): Print , and when you add a Word document that is downloaded to a local, it appears as follows:

For the third problem, there are some style incompatibility issues, such as the underline of the related attributes below the top headline:

We added the border-bottom:1px solid #545454 to the style in HTML, which is the Blue Code section, which is:but the underscore is not displayed because it is not recognized in Word. such as:

The workaround is to make the change according to the subscript style recognized by word, that is,after you change to this style, the Word document that is downloaded to the local is underlined when it is opened.

It is better to teach fish than to teach it, and I will share with you the solution to this incompatible style:

A: Find a web version of the online editor, and then enter a few words in it, and then add the underline mark

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 ;

All right, in response to the above related issues here, if you have any questions, please put forward, we discuss the solution ha.

  • 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.