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