PHP uses phpword to generate word documents
php uses phpword to generate word documents:
Related recommendations: PHPWord Chinese user manual download
<p> <?php require_once '../libs/PHPWord/PHPWord.php'; require_once '../libs/PHPWord/PHPWord/IOFactory.php'; require_once '../../config.php'; // require_once '../common/conn.php';</p> <p>// New Word Document $PHPWord = new PHPWord();</p> <p>/**********文本格式的word text.php************/ // New portrait section</p> <p>//逗号 分割字符串 $arr = $_REQUEST['arr']; $a = explode(',',$arr); //echo $arr; date_default_timezone_set("Asia/Shanghai");//设置一个时区 $tm=date('Y-m-d H:i:s'); //exit($tm); /**********前多日雨量*********/ if(in_array('1', $a, TRUE)){ $section = $PHPWord->createSection(); $PHPWord->addFontStyle('rStyle', array('bold'=>false, 'italic'=>false, 'size'=>16)); $PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100)); $c = "前三日雨量报表"; $section->addText($c, 'rStyle', 'pStyle');</p> <p>$styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80); $styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF');</p> <p>// Define cell style arrays $styleCell = array('valign'=>'center'); // Define font style for first row $fontStyle = array('bold'=>true, 'align'=>'center'); //设置标题 $PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); $PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100));</p> <p>// Add table style $PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);</p> <p>// Add table $table = $section->addTable('myOwnTableStyle');</p> <p>// Add row设置行高 $table->addRow(500);</p> <p>$table->addCell(2300, $styleCell)->addText('站码', $fontStyle); $table->addCell(2300, $styleCell)->addText('站名', $fontStyle); $table->addCell(2300, $styleCell)->addText('雨量', $fontStyle); $table->addCell(2300, $styleCell)->addText('水文站监测类型', $fontStyle);</p> <p>$conn = mssql_connect($config['mssql']['host'],$config['mssql']['user'],$config['mssql']['password']); mssql_select_db($config['mssql']['dbname'],$conn);</p> <p>$stm = date('Y-m-d H:i:s',strtotime('-3 days')); $sql = "EXEC HNOW05_GETPPSPACE '','','".$stm."',1,1"; $res=mssql_query($sql);</p> <p>while($arr = mssql_fetch_array($res)){ //echo $arr["STCD"]."</br>"; $table->addRow(); $table->addCell(2300)->addText($arr["STCD"]); $table->addCell(2300)->addText($arr["STNM"]); $table->addCell(2300)->addText($arr["P"]); if($arr["STTP"] == 'MM'){ $table->addCell(2300)->addText('气象站'); }else if($arr["STTP"] == 'BB'){ $table->addCell(2300)->addText('蒸发站'); }else if($arr["STTP"] == 'DD'){ $table->addCell(2300)->addText('堰闸水文站'); }else if($arr["STTP"] == 'TT'){ $table->addCell(2300)->addText('落潮位站'); }else if($arr["STTP"] == 'DP'){ $table->addCell(2300)->addText('泵站'); }else if($arr["STTP"] == 'SS'){ $table->addCell(2300)->addText('墒情站'); }else if($arr["STTP"] == 'PP'){ $table->addCell(2300)->addText('雨量站'); }else if($arr["STTP"] == 'ZZ'){ $table->addCell(2300)->addText('河道水位水文站'); }else if($arr["STTP"] == 'RR'){ $table->addCell(2300)->addText('水库水文站'); }else if($arr["STTP"] == 'ZG'){ $table->addCell(2300)->addText('地下水站'); }else if($arr["STTP"] == 'ZB'){ $table->addCell(2300)->addText('分洪水位站'); } } $section->addTextBreak(2); }else{</p> <p>}</p> <p>/******地质灾害*******/ if(in_array('3', $a, TRUE)){ $section = $PHPWord->createSection(); $PHPWord->addFontStyle('rStyle', array('bold'=>false, 'italic'=>false, 'size'=>16)); $PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100)); $c = "地质灾害"; $section->addText($c, 'rStyle', 'pStyle');</p> <p>$content="根据市气象局未来24小时降雨预报和市水利局实时降雨数据,市国土资源局进行了地质灾害预报, 请有关部门关注</p> <p>实时预警信息,做好地质灾害防范工作"; $section->addText($content); // Add image elements $section->addImage("images/image001.jpg", array('width'=>600, 'height'=>480, 'align'=>'center')); }else{</p> <p>} // Save File $fileName = "word报表".date("YmdHis"); header("Content-type: application/vnd.ms-word"); header("Content-Disposition:attachment;filename=".$fileName.".docx"); header('Cache-Control: max-age=0'); $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); ?> </p>
The above is the content of php using phpword to generate word documents. For more related content, please pay attention to the PHP Chinese website (www. php.cn)!
Related articles:
How to export and generate word from php
Generate a word document from a web page in a php program and provide downloadable example code

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











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.

The solution to the problem that there is no rotation button in the Word text box: After opening the compatibility mode document, press the F12 key to save it as a higher version, and then open it again.

Reasons why the word document cannot be edited: 1. The word document is locked, unexpected power outages and unexpected machine shutdowns will cause system file abnormalities; 2. The word file is damaged due to improper computer operation, computer viruses, storage device errors or file transfer problems. Caused by; 3. The word document is set to read-only mode, which usually occurs in a shared document environment; 4. An error occurs in the word program and an error message is seen.

Solution to word text overflowing the boundary: 1. Right-click the mouse in the blank space and click the "Table Properties" option; 2. Uncheck the specified height of the size in the table in the "Table Properties" interface; 3. Click OK to solve the problem The problem that the text in Word exceeds the right boundary of the page.

After editing the document, we will save the document to provide convenience for editing and modifying the document next time. Sometimes we can modify it directly after clicking on the edited document, but sometimes for some unknown reason, there is no response no matter how we click on the word document, and the command will not be executed. , what should I do if the word document cannot be edited? Don’t worry, the editor will help you solve this problem. Let’s take a look at the operation process. After opening a Word document, when editing text, you will see a "Restrict Editing" prompt displayed on the right side of the page, as shown in the figure below. 2. You need to cancel editing and you need to know the set password. Click "Stop Protection" below the pop-up prompt, as shown in the figure below. 3. Then enter the password in the "Unprotect Document" dialog box and click OK, as shown in the figure below.

CakePHP is a popular PHP development framework that aims to help developers build web applications faster and easier. PHPWord is a PHP library for Microsoft Office Word documents. It provides many useful functions for processing Word documents. In this article, we will explore how to use PHPWord in CakePHP so that developers can easily generate and process Word documents. 1. Install PHPWord

Solution to the problem that the font format of subdocuments has changed after the Word document is split: 1. Before splitting the document in outline mode, select the text content to create a new style and give the style a unique name; 2. Select the For the second paragraph of text content, set all the remaining text content to the new style format through the function of selecting similar text; 3. Enter the outline mode to split the document. After the operation is completed, open the subdocument. The text font format is the new style content before splitting. .
