


Generate a web page into a word document in the php program and provide downloadable example code
Generate content in the php program file into the word document and provide the implementation code for the download function. Friends who need it can refer to it
In this article, we mainly solve two problems:
1: How to put html in php Generate the content in the html into the word document
2: When php generates the content in html into the word document, the problem is not displayed in the center, that is, it will be displayed according to the web view by default.
3: When PHP generates content in HTML into a word document, related style incompatibility issues
Text:
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <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> </head>'; echo '<body><table class="table_dayin"> <caption class="table_caption">'; echo "数字化教学系统电子备课稿<br> <span>学科 <em style="border-bottom: 1px solid #545454;">语文</em>学校 <em style="border-bottom: 1px solid #545454;">实验中学</em></span> </caption>"; echo '</table></body></html>'; ob_start(); //打开缓冲区 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();//输出全部内容到浏览器
Note: The above code part provides the function of generating content in the PHP program file into a word document and providing a download function.
In response to the second question, after the word document downloaded to the local is opened, it is displayed in the web view by default: as shown below:
Displayed in the default web view:
If it is displayed in the normal page view, You need to add a line of xml mark in the header for setting (blue code part):
Regarding the third problem, there are some style incompatibility issues, such as the underline annotation of the relevant attributes under the big title at the top:
Our style in html The style border-bottom: 1px solid #545454; has been added (blue code part), that is: , but the underline is still not displayed because in 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, it will be downloaded to the local After the word document is opened, the underline mark 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, and then do whatever you want in it Enter a few words, and then add an underline mark
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 mark 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.
Related articles:
php uses phpword to generate word documents

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment