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

Source: Internet
Author: User
in this article, we mainly address two questions:

1: How to build HTML content into a Word document in PHP
2:php when the content in HTML is generated in a Word document, the problem is not centered, which is displayed by default in Web view.
3:php when you build content in HTML into a Word document, the related styles are incompatible.

Body:
Copy Code code as follows:

Echo ' <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<xml><w:WordDocument><w:View>Print</w:View></xml>
<script src= "Includes/js/ztree/js/jquery-1.4.4.min.js" type= "Text/javascript" ></script>
Echo ' <body><table class= "Table_dayin" >
<caption class= "Table_caption" >;
echo "Digital teaching system electronic preparation manuscript <br>
<span> discipline <em style= "border-bottom:1px solid #545454;" > Language </em> School <em style= "border-bottom:1px solid #545454;" > Experimental Secondary School </em></span>
</caption> ";
Echo ' </table></body>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 browser

Note: The above Code section provides the ability to generate content in a PHP program file into a Word document and provide downloads.
For question 2nd, the download to the local Word document opens and displays the default following the Web view: The following illustration:
Display in Default Web view:

If displayed in normal Page view, you need to add a line of XML labels to the header (Blue Code section): <xml><w:worddocument><w:view>print</w:view ></xml>, after adding the download to the local Word document opens, displays the following image:

The third problem is that there are some incompatible style issues, such as the underlined caption of the related attributes under the top headline:

We added the border-bottom:1px solid #545454 to the styles in HTML (the Blue Code section), which is: <em style= "border-bottom:1px solid #545454;" , but underscores are not displayed because they are not recognized in Word. The following figure:

The workaround is to make the change according to the subscript style that Word recognizes: <em style= "text-decoration:underline;" After changing to this style, the underline is displayed when the Word document that is downloaded to the local is opened.

Give to the fish, as to teach the fishing, I put my resolution on this solution is incompatible with the solution to share with you:

One: Find a web version of the online editor, and then enter a few words inside, and then add an underscore 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; instead of the style label in HTML: border-bottom:1px solid #545454 ;

Well, for the above related problems come here, if there are 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.