線上書籍

Home

[1012]PHP進階開發及TadTools工具應用

<?php include_once "header_admin.php"; require_once '../class/PHPWord.php'; $PHPWord = new PHPWord(); //$PHPWord->setDefaultFontName('標楷體'); //設定預設字型 $PHPWord->setDefaultFontSize(12); //設定預設字型大小 //頁面設定(orientation 的值可以是橫向 landscape 或直向portrait。設定項目有:orientation、marginTop、marginLeft、marginRight、marginBottom、borderTopSize、borderTopColor、borderLeftSize、borderLeftColor、borderRightSize、borderRightColor、borderBottomSize、borderBottomColor) $sectionStyle = array('orientation' => 'landscape'); $section = $PHPWord->createSection($sectionStyle); $fontStyle = array('color'=>'660000', 'size'=>20, 'bold'=>true); //文字樣式設定(可用的文字設定:size、name、bold、italic、superScript、subScript、underline、Color、fgColor) $PHPWord->addTitleStyle( 1, $fontStyle ); //設定標題樣式 $titleCount 是指標題幾 $section->addTitle( "我的通訊錄列表", 1); //新增標題($depth會對應$titleCount) $styleTable = array('borderColor'=>'000000', 'borderSize'=>6, 'cellMargin'=>50); //表格樣式(可用設定:cellMarginTop、cellMarginLeft、cellMarginRight、cellMarginBottom、cellMargin、bgColor、 borderTopSize、borderTopColor、borderLeftSize、borderLeftColor、borderRightSize、borderRightColor、borderBottomSize、borderBottomColor、borderInsideHSize、borderInsideHColor、borderInsideVSize、borderInsideVColor、borderSize、borderColor) $styleFirstRow = array('bgColor'=>'66BBFF'); //首行樣式 $PHPWord->addTableStyle('myTable', $styleTable, $styleFirstRow); //建立表格樣式 $table = $section->addTable('myTable');//建立表格 $table->addRow(); //新增一列 //$cellStyle =array('bgColor'=>'C0C0C0'); $cellStyle=''; //儲存格樣式(設定項:valign、textDirection、bgColor、borderTopSize、borderTopColor、borderLeftSize、borderLeftColor、borderRightSize、borderRightColor、borderBottomSize、borderBottomColor) $table->addCell(1000, $cellStyle)->addText('群組'); $table->addCell(5000, $cellStyle)->addText('姓名'); $table->addCell(2000, $cellStyle)->addText('電話'); $table->addCell(2000, $cellStyle)->addText('信箱'); $table->addCell(3000, $cellStyle)->addText('生日'); $table->addCell(9000, $cellStyle)->addText('地址'); $sql = "select * from `".$xoopsDB->prefix("contact")."` "; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); $cate=get_contact_cate_all(); while($all=$xoopsDB->fetchArray($result)){ //以下會產生這些變數: $tel , $email , $name , $gsn , $sn , $birthday , $zip , $county , $city , $addr foreach($all as $k=>$v){ $$k=$v; } $table->addRow(); //新增一列 $table->addCell(1000, $cellStyle)->addText($cate[$gsn]['title']); $table->addCell(5000, $cellStyle)->addText($name); $table->addCell(2000, $cellStyle)->addText($tel); $table->addCell(2000, $cellStyle)->addText($email); $table->addCell(3000, $cellStyle)->addText($birthday); $table->addCell(9000, $cellStyle)->addText("{$zip} {$county}{$city}{$addr}"); } /* $section->addText('款式新穎的牛仔褲、牛仔裙穿了幾年後,通常就會被遺忘拋棄在衣櫃的深處,或是進了舊衣回收桶中。但對於來自英國的藝術家伊恩‧貝瑞(Ian Berry)來說,這些丹寧布都是他從事創作最得力的工具,無論布料有多小都不願意丟棄。'); $section->addTextBreak(); //換行,可指定換幾行 $fontStyle = array('color'=>'006699', 'size'=>18, 'bold'=>true); //文字樣式設定(可用的文字設定:size、name、bold、italic、superScript、subScript、underline、Color、fgColor) $paragraphStyle=array('align' => 'both', 'spaceBefore'=>300, 'spacing'=>100); //段落設定(可用設定:align、spaceBefore、spaceAfter、spacing) $section->addText('根據英國《每日郵報》(Daily Mail)報導,原先為藝術總監、現年28歲的伊恩‧貝瑞,近來已成為藝術界鼎鼎大名的「丹寧布之神」。2006年,伊恩自大學返回老家,在房間中無意翻出許多老舊的牛仔布,靈機一動便將這些碎布拼湊成畫,開啟了伊恩的創作之門。' , $fontStyle , $paragraphStyle); */ header('Content-Type: application/vnd.ms-word'); $filename=iconv('utf-8','big5','通訊錄'); header("Content-Disposition: attachment;filename={$filename}.docx"); header('Cache-Control: max-age=0'); $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); ?>