:::
所有書籍
「[1042] XOOPS模組開發進階」目錄
MarkDown
8-3 /pdf.php (多檔下載版)
1. jquery入門及連動選單
1-1 /templates/phone_book_index_b3.html
1-2 /index.php
1-3 /ajax.php
2. 表單驗證及點擊編輯
2-1 /admin/main.php
2-2 /templates/phone_book_adm_main_b3.html
2-3 /index.php
2-4 /templates/phone_book_index_b3.html
2-5 /save_phone_book.php
2-6 /get_name.php
3. 自適應表格及拉動排序
3-1 /index.php
3-2 /templates/phone_book_index_b3.html
3-3 /admin/cate.php
3-4 /templates/phone_book_adm_cate_b3.html
3-5 /admin/main.php
3-6 /templates/phone_book_adm_main_b3.html
3-7 (利用FooTable的分頁+json功能)/index.php
3-8 (利用FooTable的分頁+json功能)/templates/phone_book_index_b3.html
3-9 (利用FooTable的分頁+json功能)/columns.json
3-10 (利用FooTable的分頁+json功能)/rows.json
3-11 (舊版FooTable)/index.php
3-12 (舊版FooTable)/templates/phone_book_index_b3.html
3-13 (舊版FooTable)tadtools/FooTable.php
4. 大小月曆應用
4-1 /templates/phone_book_adm_main_b3.html
4-2 /interface_menu.php
4-3 /birthday.php
4-4 /templates/phone_book_birthday_b3.html
4-5 /xoops_version.php
4-5 /get_event.php
5. Google圖表應用及頁籤
5-1 /interface_menu.php
5-2 /chart.php
5-3 /templates/phone_book_chart_b3.html
5-4 /xoops_version.php
5-5 /ajax.php
5-6 /templates/phone_book_index_b3.html
5-7 /index.php
5-8 /templates/phone_book_adm_main_b3.html
6. 各種文字檔的匯出匯入
6-1 /interface_menu.php
6-2 /html.php
6-3 /index.php
6-4 /function.php
6-5 /csv.php
6-6 /templates/phone_book_adm_main_b3.html
6-7 /admin/main.php
6-8 /json.php
6-9 /get_json.php
6-10 資料庫語法
7. Excel的匯出與匯入
7-1 /header.php
7-2 /excel.php
7-3 /test.php
7-4 /excel_one.php
7-5 /templates/phone_book_adm_main_b3.html
7-6 /admin/main.php
7-7 /index.php
7-8 /templates/phone_book_index_b3.html
8. 產生PDF檔
8-1 /header.php
8-2 /pdf.php
8-3 /pdf.php (多檔下載版)
9. 輸出Word檔及圖片檔
9-1 /header.php
9-2 /word.php
9-3 /index.php
9-4 /templates/phone_book_index_b3.html
9-1 /header.php
\[1042\] XOOPS模組開發進階 ==================== [](http://www.tad0616.net/uploads/tad_book3/file/39/9.pdf) ### 一、 關於phpWord(<http://phpword.codeplex.com>) 1. PHPWord和PHPExcel是同一個單位所寫出的PHP物件,可用來產生docx檔。 2. 需要的環境如下:PHP 5.2.x 以上、ZipArchive、xmllib等PHP衍生函式庫 3. 若是您的Office是2007以下,那麼可能需要Microsoft Office Compatibility Pack(http://www.microsoft.com/zh-tw/download/details.aspx?id=3)才能開啟之(共37.2MB)。PHPWord無法產生2003的doc檔(因為非公開格式)。 4. 建立一個word檔的基本結構如下: ``` <pre class="brush:php;"> <?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'); ``` 5. 若有用到長度,其單位為twip,1twip=1/1440英吋,1 cm=0.4 in=576 twip 6. 一些預設及建立頁面設定功能 ``` <pre class="brush:php;"> $PHPWord->setDefaultFontName('微軟正黑體'); //設定預設字型 $PHPWord->setDefaultFontSize(10); //設定預設字型大小 $sectionStyle = array('orientation' => null, 'marginLeft' => 900); //頁面設定 $section = $PHPWord->createSection($sectionStyle); //建立一個頁面 ``` - (1) orientation 的值可以是橫向landscape或直向portrait。設定項目有:orientation、 marginTop、marginLeft、marginRight、marginBottom、borderTopSize、borderTopColor、borderLeftSize、borderLeftColor、borderRightSize、borderRightColor、borderBottomSize、borderBottomColor 7. 新增標題($titleCount 是指標題N,$depth會對應$titleCount) ``` <pre class="brush:php;"> $fontStyle = array('color'=>'006699', 'size'=>18, 'bold'=>true); //文字樣式設定 $PHPWord->addTitleStyle( $titleCount, $fontStyle, $styleParagraph); //設定標題樣式 $section->addTitle( '通訊錄', $depth ); //新增標題 ``` - (1) 可用的文字設定:size(文字大小)、name(字型)、bold(粗體)、italic(斜體)、superScript(上標)、subScript(下標)、 underline(底線)、strikethrough(刪除線)、Color(文字顏色)、fgColor(背景色) 8. underline 底線可用的常數: ``` <pre class="brush:php;"> 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'; ``` 9. fgColor 背景色可用的常數 ``` <pre class="brush:php;"> 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'; ``` 10. 新增文字及相關文字設定 ``` <pre class="brush:php;"> $paragraphStyle=array('align' => 'both', 'spaceAfter'=>300); //段落設定 $section->addText('內容', $fontStyle, $paragraphStyle); //新增文字段落 ``` - (1) 可用段落設定:align、spaceBefore、spaceAfter、spacing 11. 換行及換頁 ``` <pre class="brush:php;"> $section->addTextBreak(2); //換行,可指定換幾行 $section->addPageBreak(); //換頁 ``` 12. 插入連結和圖片,$style 可用設定:width、height、align,單位為px ``` <pre class="brush:php;"> $section->addLink( $linkSrc, $linkName, $fontStyle, $paragraphStyle); //加入連結 $section->addImage( $src, $style ); //插入圖片 ``` 13. 插入有序或無序清單, 設定有序(TYPE\_NUMBER)或無序(TYPE\_BULLET\_FILLED)清單,$depth為階層,從0開始。 ``` <pre class="brush:php;"> $listStyle = array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER); $section->addListItem( $text, $depth, $fontStyle, $listStyle, $paragraphStyle ); //新增清單項目 ``` 14. 插入表格 ``` <pre class="brush:php;"> $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('內容'); //新增一格 ``` - (1) 表格可用設定:cellMarginTop、cellMarginLeft、cellMarginRight、cellMarginBottom、cellMargin、bgColor、borderTopSize、borderTopColor、borderLeftSize、borderLeftColor、borderRightSize、borderRightColor、borderBottomSize、borderBottomColor、borderInsideHSize、borderInsideHColor、borderInsideVSize、borderInsideVColor、borderSize、borderColor - (2) 儲存格可用設定:valign、textDirection、bgColor、borderTopSize、borderTopColor、borderLeftSize、borderLeftColor、borderRightSize、borderRightColor、borderBottomSize、borderBottomColor 15. 垂直合併除存格 ``` <pre class="brush:as3;"> $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'); ``` 看起來會像這樣: <table border="1" cellpadding="0" cellspacing="0" class="table table-bordered table-hover table-condensed" style="border-collapse: collapse; width: 300px;"> <tbody> <tr> <td rowspan="2">1</td> <td>2</td> </tr> <tr> <td>3</td> </tr> </tbody> </table> 16. 水平合併儲存格 ``` <pre class="brush:php;"> $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'); ``` 看起來會像這樣: <table border="1" cellpadding="0" cellspacing="0" class="table table-bordered table-hover table-condensed" style="border-collapse: collapse; width: 300px;"> <tbody> <tr> <td colspan="2">1</td> </tr> <tr> <td>2</td> <td>3</td> </tr> </tbody> </table> ### 二、 無中生有產生圖片 1. 使用PHP中GD函式庫:<http://php.net/manual/en/ref.image.php> 2. 基本產生圖檔方法: ``` <pre class="brush:php;"> header("Content-type: image/png"); $im = @imagecreatetruecolor(400, 100) or die("無法建立GD圖片"); imagepng($im, XOOPS_ROOT_PATH . "/uploads/{$sn}.png"); imagedestroy($im); ``` - (1) resource imagecreatetruecolor(int $寬 , int $高) //建立全彩畫布 - (2) bool imagepng(resource $im \[, string $檔名 \[, int $品質 \[, int $濾鏡\]\]\])//產生png - (3) bool imagedestroy(resource $im) //釋放記憶體 3. 產生透明背景 ``` <pre class="brush:php;"> imagesavealpha($im, true); $trans_colour = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefill($im, 0, 0, $trans_colour); ``` - (1) bool imagesavealpha ( resource $im , bool $是否保存alpha channel ) //透明色版 - (2) int imagecolorallocatealpha ( resource $ im , int $紅 , int $綠 , int $ 藍 , int $透明 )//設定含透明度的顏色,顏色值從1~255,透明值從0(不透明)~127(透明) - (3) bool imagefill ( resource $im , int $x , int $y , int $顏色設定 )//填滿顏色 4. 產生文字(各式字體練習素材:<http://soft.aizhan.com/xtmh/ziti/>)[範例字型](http://www.tad0616.net/uploads/tad_book3/file/39/font.zip) ``` <pre class="brush:php;"> $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); ``` - (1) array gd\_info ( void ) //用來取得GD函式庫的各種支援情形,若伺服器設定成支援日文編碼,那就必須進行文字的轉碼,以避免中文變成亂碼。 - (2) array imagettftext(resource $im , float $大小 , float $角度 , int $x , int $y , xint $顏色 , string $字型檔 , string $文字) //若要置中x大約是「(圖寬-字數x字尺寸x1.5)/2」,而y則是「(圖高-字尺寸)/2+字尺寸」 5. 製作縮圖(或加入為背景圖):<https://pixabay.com/> ``` <pre class="brush:php;"> $bg_im = imagecreatefromjpeg("images/bg.jpg"); imagecopyresampled($im, $bg_im, 0, 0, 0, 0, 400, 100, 1024, 768); ``` - (1) resource imagecreatefromjpeg ( string $jpg圖檔來源 ) //讀入某張圖 - (2) bool imagecopyresampled(resource $目的 , resource $來源 , int $目的\_x , int $目的\_y , int $來源\_x , int $來源\_y , int $目的寬 , int $目的高 , int $來源寬 , int $來源高) //縮放圖檔並產生新圖,若是不想讓底圖變形,來源寬和來源高可以指定成和目的寬、目的高一致,這樣就只會擷取局部,而不會使之變形。
:::
搜尋
search
進階搜尋
QR Code 區塊
快速登入
所有討論區
「PHP全端開發」線上課程討論區
XOOPS使用討論區
一般研習學員
社大學員專用
路過哈啦區
XOOPS佈景設計
XOOPS模組開發
Tad書籍區
即時留言簿
書籍目錄
總目錄
1.jquery入門及連動選單
1-1/templates/phone_book_index_b3.html
1-2/index.php
1-3/ajax.php
2.表單驗證及點擊編輯
2-1/admin/main.php
2-2/templates/phone_book_adm_main_b3.html
2-3/index.php
2-4/templates/phone_book_index_b3.html
2-5/save_phone_book.php
2-6/get_name.php
3.自適應表格及拉動排序
3-1/index.php
3-2/templates/phone_book_index_b3.html
3-3/admin/cate.php
3-4/templates/phone_book_adm_cate_b3.html
3-5/admin/main.php
3-6/templates/phone_book_adm_main_b3.html
3-7(利用FooTable的分頁+json功能)/index.php
3-8(利用FooTable的分頁+json功能)/templates/phone_book_index_b3.html
3-9(利用FooTable的分頁+json功能)/columns.json
3-10(利用FooTable的分頁+json功能)/rows.json
3-11(舊版FooTable)/index.php
3-12(舊版FooTable)/templates/phone_book_index_b3.html
3-13(舊版FooTable)tadtools/FooTable.php
4.大小月曆應用
4-1/templates/phone_book_adm_main_b3.html
4-2/interface_menu.php
4-3/birthday.php
4-4/templates/phone_book_birthday_b3.html
4-5/xoops_version.php
4-5/get_event.php
5.Google圖表應用及頁籤
5-1/interface_menu.php
5-2/chart.php
5-3/templates/phone_book_chart_b3.html
5-4/xoops_version.php
5-5/ajax.php
5-6/templates/phone_book_index_b3.html
5-7/index.php
5-8/templates/phone_book_adm_main_b3.html
6.各種文字檔的匯出匯入
6-1/interface_menu.php
6-2/html.php
6-3/index.php
6-4/function.php
6-5/csv.php
6-6/templates/phone_book_adm_main_b3.html
6-7/admin/main.php
6-8/json.php
6-9/get_json.php
6-10資料庫語法
7.Excel的匯出與匯入
7-1/header.php
7-2/excel.php
7-3/test.php
7-4/excel_one.php
7-5/templates/phone_book_adm_main_b3.html
7-6/admin/main.php
7-7/index.php
7-8/templates/phone_book_index_b3.html
8.產生PDF檔
8-1/header.php
8-2/pdf.php
8-3/pdf.php (多檔下載版)
9.輸出Word檔及圖片檔
9-1/header.php
9-2/word.php
9-3/index.php
9-4/templates/phone_book_index_b3.html
展開
|
闔起
線上使用者
25
人線上 (
4
人在瀏覽
線上書籍
)
會員: 0
訪客: 25
更多…
:::
主選單
NTPC OpenID
活動報名
模組控制台
進階區塊管理
站長工具箱(急救版)
網站地圖
Tad Tools 工具包
站長工具箱
行事曆
討論留言
嵌入區塊模組
快速登入
網站計數器
好站連結
最新消息
檔案下載
線上書籍
電子相簿
影音播放
常見問題
萬用表單
友站消息
社大學員
新聞
下載
教材
影音
討論
其他選單
好站連結
行事曆
電子相簿
常見問題
萬用表單
即時留言簿
友站消息
社大學員
登入
登入
帳號
密碼
登入