setDefaultFontName('微軟正黑體'); //設定預設字型 $PHPWord->setDefaultFontSize(10); //設定預設字型大小 $sectionStyle = array('orientation' => null, 'marginLeft' => 900, 'marginRight' => 900); //頁面設定 $section = $PHPWord->createSection($sectionStyle); //建立一個頁面 //內容設定 $fontStyle1 = array('name'=>'標楷體', 'color'=>'0000ff', 'size'=>24); //文字樣式設定 $fontStyle2 = array('color'=>'ff0000', 'size'=>18, 'bold'=>true, 'bold'=>true, 'underline'=>PHPWord_Style_Font::UNDERLINE_DASH , 'fgColor'=>PHPWord_Style_Font::FGCOLOR_YELLOW ,'strikethrough'=>true); //文字樣式設定 //段落設定 $paragraphStyle=array('align' => 'center', 'spaceAfter'=>300); $PHPWord->addTitleStyle( 1, $fontStyle1, $paragraphStyle); //設定標題樣式 $PHPWord->addTitleStyle( 2, $fontStyle2); //設定標題樣式 $section->addTitle( '通訊錄', 1 ); //新增標題 /*內容部份*/ // $TextfontStyle = array('name'=>'標楷體', 'color'=>'000000', 'size'=>12); //文字樣式設定 // $TextparagraphStyle=array('align' => 'left', 'spaceAfter'=>576); // $content1="頂新案一審判無罪,台北市長柯文哲今天表示,這是總統大選迄今為止,「最大的催票行為」。 // 柯文哲昨晚到社子島進行Homestay,今天一早還到當地地藏禪寺和地皎法師、台北市議員吳思瑤及徐世勳、當地居民和里長一同吃素齋早餐祈福。 // 媒體餐後聯訪詢問頂新製油公司前董事長魏應充被判無罪,怎看?"; // $content2="柯文哲表示,這是總統大選迄今為止,這是最大的催票行為,用膝蓋想也知道。 // 記者追問是否把挺綠的票催出來?柯文哲笑著反問「妳認為哩?」。 // 彰化地方法院昨天判決頂新製油案無罪。法官根據專業鑑定,認為酸價不是作為油品最終衛生認定基礎;法院採完整的檢驗,總極性化合物也未如檢方所稱達危害程度。"; // $section->addText( $content1, $TextfontStyle ,$TextparagraphStyle); //新增內容 // $section->addText( $content2, $TextfontStyle ,$TextparagraphStyle); //新增內容 /*表格部份*/ $styleTable=array('borderColor' => '000000', 'borderSize' => 4, 'cellMargin' => 30); //表格樣式 $styleFirstRow = array('bgColor' => '66BBFF'); //首行樣式 $PHPWord->addTableStyle('myTable', $styleTable, $styleFirstRow); //建立表格樣式 $cellStyle = array('bgColor' => 'ffffff'); //儲存格樣式 $table = $section->addTable('myTable'); //建立表格 if($sn){ $myts = MyTextSanitizer::getInstance(); $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where `sn` = '{$sn}' "; $result = $xoopsDB->query($sql) or web_error($sql); $all = $xoopsDB->fetchArray($result); //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note foreach ($all as $k => $v) { $$k = $v; } //取得分類資料(phone_book_cate) //$phone_book_cate_arr = get_phone_book_cate($cate_sn); //過濾讀出的變數值 $name = $myts->htmlSpecialChars($name); $birthday = $myts->htmlSpecialChars($birthday); $phone = $myts->htmlSpecialChars($phone); $email = $myts->htmlSpecialChars($email); $zip = $myts->htmlSpecialChars($zip); $county = $myts->htmlSpecialChars($county); $city = $myts->htmlSpecialChars($city); $addr = $myts->htmlSpecialChars($addr); $note = $myts->displayTarea($note, 0, 1, 0, 1, 1); $table->addRow(); //新增一列 $table->addCell(1800, array('gridSpan' => '3', 'bgColor' => 'ffffff'))->addText($name.'聯絡方式'); //新增一格 $table->addRow(); //新增一列 $table->addCell(1800, array('vMerge' => 'restart', 'bgColor' => 'ffffff'))->addText('相片'); //新增一格 $table->addCell(1800, $cellStyle)->addText('姓名'); //新增一格 $table->addCell(3000, $cellStyle)->addText($name); //新增一格 $table->addRow(); //新增一列 $table->addCell(1800, array('vMerge' => 'fusion')); //新增一格 $table->addCell(1800, $cellStyle)->addText('生日'); //新增一格 $table->addCell(3000, $cellStyle)->addText($birthday); //新增一格 $table->addRow(); //新增一列 $table->addCell(1800, array('vMerge' => 'fusion')); //新增一格 $table->addCell(1800, $cellStyle)->addText('電話'); //新增一格 $table->addCell(3000, $cellStyle)->addText($phone); //新增一格 $table->addRow(); //新增一列 $table->addCell(1800, array('vMerge' => 'fusion')); //新增一格 $table->addCell(1800, $cellStyle)->addText('信箱'); //新增一格 $table->addCell(3000, $cellStyle)->addText($email); //新增一格 $table->addRow(); //新增一列 $table->addCell(1800, array('vMerge' => 'fusion')); //新增一格 $table->addCell(1800, $cellStyle)->addText('地址'); //新增一格 $table->addCell(3000, $cellStyle)->addText($zip.$county.$city.$addr); //新增一格 }else{ $and_name=$and_cate_sn=$and_city=""; if(!empty($def_keyword)){ $and_name="and (`name` like '%{$def_keyword}%' or `city` like '%{$def_keyword}%' or `county` like '%{$def_keyword}%' or `addr` like '%{$def_keyword}%')"; }else{ $and_cate_sn = empty($def_cate_sn) ? "" : "and `cate_sn` = '{$def_cate_sn}'"; $and_county = empty($def_county) ? "" : "and `county` = '{$def_county}'"; $and_city = empty($def_city) ? "" : "and `city` = '{$def_city}'"; } //取得分類資料 $phone_book_cate_arr = get_phone_book_cate_arr(); $myts = MyTextSanitizer::getInstance(); $sql = "select * from `" . $xoopsDB->prefix("phone_book") . "` where 1 $and_cate_sn $and_county $and_city $and_name limit 0,100"; $result = $xoopsDB->query($sql) or web_error($sql); while ($all = $xoopsDB->fetchArray($result)) { //以下會產生這些變數: $sn, $cate_sn, $name, $birthday, $phone, $email, $zip, $county, $city, $addr, $note foreach ($all as $k => $v) { $$k = $v; } //過濾讀出的變數值 $name = $myts->htmlSpecialChars($name); $birthday = $myts->htmlSpecialChars($birthday); $phone = $myts->htmlSpecialChars($phone); $email = $myts->htmlSpecialChars($email); $zip = $myts->htmlSpecialChars($zip); $county = $myts->htmlSpecialChars($county); $city = $myts->htmlSpecialChars($city); $addr = $myts->htmlSpecialChars($addr); $note = $myts->displayTarea($note, 0, 1, 0, 1, 1); $table->addRow(); //新增一列 $table->addCell(1800, $cellStyle)->addText($name); //新增一格 $table->addCell(2500, $cellStyle)->addText($birthday); //新增一格 $table->addCell(2000, $cellStyle)->addText($phone); //新增一格 $table->addCell(2000, $cellStyle)->addText($email); //新增一格 $table->addCell(8000, $cellStyle)->addText($zip.$county.$city.$addr); //新增一格 } } header('Content-Type: application/vnd.ms-word'); header('Content-Disposition: attachment;filename=通訊錄.docx'); header('Cache-Control: max-age=0'); $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); ```
進階搜尋
30人線上 (19人在瀏覽線上書籍)
會員: 0
訪客: 30