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************/in text format
- New Portrait section
Comma-delimited string
- $arr = $_request[' arr '];
- $a = explode (', ', $arr);
- Echo $arr;
- Date_default_timezone_set ("Asia/shanghai");//Set a time zone
- $tm =date (' y-m-d h:i:s ');
- Exit ($TM);
- Multi-day rainfall *********/before/**********
- 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 = "Previous 3rd rainfall report";
- $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 ');
- Set Title
- $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 Set Line height
- $table->addrow (500);
$table->addcell (2300, $styleCell)->addtext (' station code ', $fontStyle);
- $table->addcell (2300, $styleCell)->addtext (' Station name ', $fontStyle);
- $table->addcell (2300, $styleCell)->addtext (' rainfall ', $fontStyle);
- $table->addcell (2300, $styleCell)->addtext (' Hydrological station monitoring type ', $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. "',";
- $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 (' Weather Station ');
- }else if ($arr ["STTP"] = = ' BB ') {
- $table->addcell (2300)->addtext (' Evaporation Station ');
- }else if ($arr ["STTP"] = = ' DD ') {
- $table->addcell (2300)->addtext (' Weir Sluice hydrologic station ');
- }else if ($arr ["STTP"] = = ' TT ') {
- $table->addcell (2300)->addtext (' Ebb position Station ');
- }else if ($arr ["STTP"] = = ' DP ') {
- $table->addcell (2300)->addtext (' Pumping Station ');
- }else if ($arr ["STTP"] = = ' SS ') {
- $table->addcell (2300)->addtext (' Moisture station ');
- }else if ($arr ["STTP"] = = ' PP ') {
- $table->addcell (2300)->addtext (' Rainfall Station ');
- }else if ($arr ["STTP"] = = ' ZZ ') {
- $table->addcell (2300)->addtext (' river water level hydrologic Station ');
- }else if ($arr ["STTP"] = = ' RR ') {
- $table->addcell (2300)->addtext (' Reservoir hydrological Station ');
- }else if ($arr ["STTP"] = = ' ZG ') {
- $table->addcell (2300)->addtext (' Groundwater station ');
- }else if ($arr ["STTP"] = = ' ZB ') {
- $table->addcell (2300)->addtext (' min flood Level station ');
- }
- }
- $section->addtextbreak (2);
- }else{
}
/****** Geological Hazard *******/
- 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 = "geological hazard";
- $section->addtext ($c, ' Rstyle ', ' pstyle ');
$content = "According to the City Meteorological Bureau in the next 24-hour rainfall forecast and the city water Bureau real-time rainfall data, the city land and resources department conducted a geological disaster forecast, please the relevant departments concerned
Real-time warning information, good geological disaster prevention work ";
- $section->addtext ($content);
- ADD image elements
- $section->addimage ("Images/image001.jpg", Array (' width ' =>600, ' height ' =>480, ' align ' = ' center '));
- }else{
}
- Save File
- $fileName = "Word report". 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 ');
- ?>
Copy Code |