


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

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

Word document breaks into new lines as soon as you hit the space button. This is caused by default settings, text alignment, table operations, etc. The solution is as follows: 1. Use non-line-breaking spaces to keep the text neat and aligned; 2. Adjust the default settings. In the option settings of Word, you can find the "Advanced" tab, and then uncheck the "Typesetting Options" Select the option "Automatically wrap lines when hitting the space bar"; 3. Use tab characters to keep the table aligned and avoid line wrapping problems; 4. Use text boxes, etc.

WORD is a powerful word processor. We can use word to edit various texts. In Excel tables, we have mastered the calculation methods of addition, subtraction and multipliers. So if we need to calculate the addition of numerical values in Word tables, How to subtract the multiplier? Can I only use a calculator to calculate it? The answer is of course no, WORD can also do it. Today I will teach you how to use formulas to calculate basic operations such as addition, subtraction, multiplication and division in tables in Word documents. Let's learn together. So, today let me demonstrate in detail how to calculate addition, subtraction, multiplication and division in a WORD document? Step 1: Open a WORD, click [Table] under [Insert] on the toolbar, and insert a table in the drop-down menu.

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

To set the automatic refresh of a web page, you can use the HTML "meta" tag, the JavaScript "setTimeout" function, the "setInterval" function or the HTTP "Refresh" header. Detailed introduction: 1. Use the "meta" tag of HTML. In the "<head>" tag of the HTML document, you can use the "meta" tag to set the automatic refresh of the web page; 2. The "setTimeout" function of JavaScript, etc.

Solutions to inaccessible web pages include checking the network connection, clearing the browser cache, checking the web page address, trying to use other browsers, checking the server status, checking the domain name resolution, checking the firewall and security settings and contacting the website administrator. Detailed introduction: 1. Check the network connection to ensure that the network connection is normal. You can try to open other web pages or use other devices to access to determine whether it is a network connection problem. If other web pages can be accessed normally, it may be a problem with the web page; 2. Clear the browser cache. The browser cache may cause the web page to fail to load, etc.

The browser cannot open the web page but the network is normal. There are many possible reasons. When this problem occurs, we need to investigate step by step to determine the specific cause and solve the problem. First, determine whether the webpage cannot be opened is limited to a specific browser or whether all browsers cannot open the webpage. If only one browser cannot open the web page, you can try to use other browsers, such as Google Chrome, Firefox, etc., for testing. If other browsers are able to open the page correctly, the problem is most likely with that specific browser, possibly

How to solve the problem of web pages not opening With the rapid development of the Internet, people increasingly rely on the Internet to obtain information, communicate and entertain. However, sometimes we encounter the problem that the web page cannot be opened, which brings us a lot of trouble. This article will introduce you to some common methods to help solve the problem of web pages not opening. First, we need to determine why the web page cannot be opened. Possible reasons include network problems, server problems, browser settings problems, etc. Here are some solutions: Check network connection: First, we need
