-
-
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();< ;/p>
/**********Text format word text.php************/
- // New portrait section
//Comma separated 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);
- /**********Rain volume in recent days*********/
- 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 three days' 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 the 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');
- < p>// Add row to set the row height
- $table->addRow(500);
$table->addCell(2300, $styleCell)->addText('site 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."',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('Weather Station');
- }else if ($arr["STTP"] == 'BB'){
- $table->addCell(2300)->addText('Evaporation Station');
- }else if($arr["STTP"] == 'DD'){
- $table->addCell(2300)->addText('Weir Gate Hydrological Station');
- }else if($arr["STTP"] == 'TT'){
- $table ->addCell(2300)->addText('Ebb Tide Station');
- }else if($arr["STTP"] == 'DP'){
- $table->addCell(2300)-> ;addText('Pumping Station');
- }else if($arr["STTP"] == 'SS'){
- $table->addCell(2300)->addText('Pumping Station');
- }else if($arr["STTP"] == 'PP'){
- $table->addCell(2300)->addText('Rain Gauge Station');
- }else if($arr["STTP" ] == 'ZZ'){
- $table->addCell(2300)->addText('River water level hydrological station');
- }else if($arr["STTP"] == 'RR'){
- $table->addCell(2300)->addText('Reservoir Hydrological Station');
- }else if($arr["STTP"] == 'ZG'){
- $table->addCell(2300 )->addText('Underground water station');
- }else if($arr["STTP"] == 'ZB'){
- $table->addCell(2300)->addText('Flood level Station');
- }
- }
- $section->addTextBreak(2);
- }else{
}
/******Geological disaster*******/
- 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 Hazards";
- $section->addText($c, 'rStyle', 'pStyle');
$content="Based on the 24-hour rainfall forecast of the Municipal Meteorological Bureau and the real-time rainfall data of the Municipal Water Conservancy Bureau, the Municipal Land and Resources Bureau has made a geological disaster forecast. Please pay attention to the relevant departments
Real-time warning information to prevent geological disasters";
- $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
|