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 "Digital teaching system e-Lesson Draft
Experimental Middle School of subject
language schools
"; Echo."
';
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 ...