<?php include_once "header.php"; require_once TADTOOLS_PATH . "/PHPWord.php"; $PHPWord = new PHPWord(); //內容設定 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');
$PHPWord->setDefaultFontName('微軟正黑體'); //設定預設字型 $PHPWord->setDefaultFontSize(10); //設定預設字型大小 $sectionStyle = array('orientation' => null, 'marginLeft' => 900); //頁面設定 $section = $PHPWord->createSection($sectionStyle); //建立一個頁面
$fontStyle = array('color'=>'006699', 'size'=>18, 'bold'=>true); //文字樣式設定 $PHPWord->addTitleStyle( $titleCount, $fontStyle, $styleParagraph); //設定標題樣式 $section->addTitle( '通訊錄', $depth ); //新增標題
PHPWord_Style_Font::UNDERLINE_NONE = 'none'; PHPWord_Style_Font::UNDERLINE_DASH = 'dash'; PHPWord_Style_Font::UNDERLINE_DASHHEAVY = 'dashHeavy'; PHPWord_Style_Font::UNDERLINE_DASHLONG = 'dashLong'; PHPWord_Style_Font::UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy'; PHPWord_Style_Font::UNDERLINE_DOUBLE = 'dbl'; PHPWord_Style_Font::UNDERLINE_DOTHASH = 'dotDash'; PHPWord_Style_Font::UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy'; PHPWord_Style_Font::UNDERLINE_DOTDOTDASH = 'dotDotDash'; PHPWord_Style_Font::UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy'; PHPWord_Style_Font::UNDERLINE_DOTTED = 'dotted'; PHPWord_Style_Font::UNDERLINE_DOTTEDHEAVY = 'dottedHeavy'; PHPWord_Style_Font::UNDERLINE_HEAVY = 'heavy'; PHPWord_Style_Font::UNDERLINE_SINGLE = 'single'; PHPWord_Style_Font::UNDERLINE_WAVY = 'wavy'; PHPWord_Style_Font::UNDERLINE_WAVYDOUBLE = 'wavyDbl'; PHPWord_Style_Font::UNDERLINE_WAVYHEAVY = 'wavyHeavy'; PHPWord_Style_Font::UNDERLINE_WORDS = 'words';
PHPWord_Style_Font::FGCOLOR_YELLOW = 'yellow'; PHPWord_Style_Font::FGCOLOR_LIGHTGREEN = 'green'; PHPWord_Style_Font::FGCOLOR_CYAN = 'cyan'; PHPWord_Style_Font::FGCOLOR_MAGENTA = 'magenta'; PHPWord_Style_Font::FGCOLOR_BLUE = 'blue'; PHPWord_Style_Font::FGCOLOR_RED = 'red'; PHPWord_Style_Font::FGCOLOR_DARKBLUE = 'darkBlue'; PHPWord_Style_Font::FGCOLOR_DARKCYAN = 'darkCyan'; PHPWord_Style_Font::FGCOLOR_DARKGREEN = 'darkGreen'; PHPWord_Style_Font::FGCOLOR_DARKMAGENTA = 'darkMagenta'; PHPWord_Style_Font::FGCOLOR_DARKRED = 'darkRed'; PHPWord_Style_Font::FGCOLOR_DARKYELLOW = 'darkYellow'; PHPWord_Style_Font::FGCOLOR_DARKGRAY = 'darkGray'; PHPWord_Style_Font::FGCOLOR_LIGHTGRAY = 'lightGray'; PHPWord_Style_Font::FGCOLOR_BLACK = 'black';
$paragraphStyle=array('align' => 'both', 'spaceAfter'=>300); //段落設定 $section->addText('內容', $fontStyle, $paragraphStyle); //新增文字段落
$section->addTextBreak(2); //換行,可指定換幾行 $section->addPageBreak(); //換頁
$section->addLink( $linkSrc, $linkName, $fontStyle, $paragraphStyle); //加入連結 $section->addImage( $src, $style ); //插入圖片
$listStyle = array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER); $section->addListItem( $text, $depth, $fontStyle, $listStyle, $paragraphStyle ); //新增清單項目
$styleTable=array('borderColor' => '006699', 'borderSize' => 6, 'cellMargin' => 50); //表格樣式 $styleFirstRow = array('bgColor' => '66BBFF'); //首行樣式 $PHPWord->addTableStyle('myTable', $styleTable, $styleFirstRow); //建立表格樣式 $table = $section->addTable('myTable'); //建立表格 $cellStyle = array('textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR, 'bgColor' => 'C0C0C0'); //儲存格樣式 $table->addRow(); //新增一列 $table->addCell(2000, [$cellStyle])->addText('內容'); //新增一格
$table = $section->addTable(); $table->addRow(); $table->addCell(100,array('vMerge' => 'restart'))->addText('1'); $table->addCell(100)->addText('2'); $table->addRow(); $table->addCell(100,array('vMerge' => 'fusion')); $table->addCell(100)->addText('3');
看起來會像這樣:
1 | 2 |
3 |
水平合併儲存格
$table = $section->addTable(); $table->addRow(); $table->addCell(100,array('gridSpan' => '2'))->addText('1'); $table->addRow(); $table->addCell(100)->addText('2'); $table->addCell(100)->addText('3');
看起來會像這樣:
1 | |
2 | 3 |
header("Content-type: image/png"); $im = @imagecreatetruecolor(400, 100) or die("無法建立GD圖片"); imagepng($im, XOOPS_ROOT_PATH . "/uploads/{$sn}.png"); imagedestroy($im);
imagesavealpha($im, true); $trans_colour = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefill($im, 0, 0, $trans_colour);
$text_color = imagecolorallocatealpha($im, 0, 0, 0, 50); $gd = gd_info(); if ($gd['JIS-mapped Japanese Font Support']) { $name = iconv("UTF-8", "shift_jis", $name); } imagettftext($im, 20, 0, 0, 60, $text_color, "font.ttf", $name);
$bg_im = imagecreatefromjpeg("images/bg.jpg"); imagecopyresampled($im, $bg_im, 0, 0, 0, 0, 400, 100, 1024, 768);