Generate a Word document in a PHP program and provide the downloaded instance code

Source: Internet
Author: User
In the PHP program files to generate content into the Word document and provide the download function implementation code, the need for friends can refer to the following

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 ' 

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 to set it (Blue Code section): <xml><w:worddocument><w:view>print</w:view ></xml> After 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 have added the border-bottom:1px solid #545454 to the style in HTML, this style (Blue Code section), namely: <em style= "border-bottom:1px solid #545454;" But the underscore is not displayed because it is not recognized in Word. Such as:

The workaround is to make the changes according to the subscript style recognized by word: <em style= "text-decoration:underline;" After you change to this style, the Word document that you downloaded to your local file opens with an underscore displayed.

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.

Related articles:

PHP uses Phpword to generate Word documents

PHP Export method to generate word

Three ways to implement a Word document generated by PHP

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