php使用phpword插件生成word文档
php使用phpword插件生成word文档,有需要的朋友可以参考参考。
<?php require_once '../libs/PHPWord/PHPWord.php'; require_once '../libs/PHPWord/PHPWord/IOFactory.php'; require_once '../../config.php'; // require_once '../common/conn.php'; // New Word Document $PHPWord = new PHPWord(); /**********文本格式的word text.php************/ // New portrait section //逗号 分割字符串 $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'); $styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80); $styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF'); // 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)); // Add table style $PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow); // Add table $table = $section->addTable('myOwnTableStyle'); // Add row设置行高 $table->addRow(500); $table->addCell(2300, $styleCell)->addText('站码', $fontStyle); $table->addCell(2300, $styleCell)->addText('站名', $fontStyle); $table->addCell(2300, $styleCell)->addText('雨量', $fontStyle); $table->addCell(2300, $styleCell)->addText('水文站监测类型', $fontStyle); $conn = mssql_connect($config['mssql']['host'],$config['mssql']['user'],$config['mssql']['password']); mssql_select_db($config['mssql']['dbname'],$conn); $stm = date('Y-m-d H:i:s',strtotime('-3 days')); $sql = "EXEC HNOW05_GETPPSPACE '','','".$stm."',1,1"; $res=mssql_query($sql); while($arr = mssql_fetch_array($res)){ //echo $arr["STCD"]." "; $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{ } /******地质灾害*******/ 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'); $content="根据市气象局未来24小时降雨预报和市水利局实时降雨数据,市国土资源局进行了地质灾害预报,请有关部门关 注 实时预警信息,做好地质灾害防范工作"; $section->addText($content); // Add image elements $section->addImage("images/image001.jpg", array('width'=>600, 'height'=>480, 'align'=>'center')); }else{ } // 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'); ?>
上面是我整理给大家的在php中使用phpword插件生成word文档,希望今后会对大家有帮助。
相关文章:
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
4 몇 주 전ByDDD
Windows 11 KB5054979의 새로운 기능 및 업데이트 문제를 해결하는 방법
3 몇 주 전ByDDD
Atomfall에서 크레인 제어 키 카드를 찾을 수 있습니다
4 몇 주 전ByDDD
<s> : 데드 레일 - 모든 도전을 완료하는 방법
1 몇 달 전ByDDD
Atomfall Guide : 항목 위치, 퀘스트 가이드 및 팁
1 몇 달 전ByDDD

뜨거운 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음
