In this article, we mainly solve two problems:
1: How to generate the content in html into a word document in php
2: When PHP generates the content in HTML into a word document, the display problem is not centered, that is, it will be displayed according to the web view by default.
3: When PHP generates content in HTML into a word document, there are related style incompatibility issues
Text:
echo '
;
echo '
';
echo "Digital teaching system electronic lesson preparation manuscript
SubjectsChineseSchoolExperimental Middle School
";
echo '
';
ob_start(); //Open the 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 above code part provides the function of generating content in the PHP program file into the word document and providing the download function.
In response to the second question, after opening the word document downloaded locally, it will be displayed in the web view by default: as shown below:
Displayed according to the default web view:
If it is displayed according to the normal page view, you need to add a line of xml mark in the header for setting (blue code part):
Print , the word document downloaded to the local after adding is displayed as shown below:
Regarding the third problem, there are some style incompatibility issues, such as the underlined annotation of relevant attributes under the big title at the top:
We added the border-bottom: 1px solid #545454; style (blue code part) to the style in html, that is:
, but underlined It is still not displayed because it is not recognized in Word. As shown below:
The solution is to change it according to the subscript style recognized by word, that is: . After changing to this style, there will be underlines after the word document downloaded to the local is opened. The sign is displayed.
It is better to teach someone to fish than to teach him to fish. I will share with you my solution to this style incompatibility:
1: Find a web version of the online editor, then enter a few words in it, and then add an underline
2: Then click the View Source Code button on the editor. You can see that the underlined attribute just added is text-decoration: underline; instead of the style label in html: border-bottom: 1px solid #545454;
Okay, that’s it for the above related issues. If you have any questions, please ask them and we will discuss and solve them together.
points
http://www.bkjia.com/PHPjc/477948.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477948.htmlTechArticleIn this article, we mainly solve two problems: 1: How to generate the content in html to 2 in word document: When php generates the content in html into the word document, the display problem is not centered,...