{"id":2547,"date":"2015-09-29T11:08:58","date_gmt":"2015-09-29T03:08:58","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=2547"},"modified":"2017-05-08T13:30:01","modified_gmt":"2017-05-08T05:30:01","slug":"%e4%bd%bf%e7%94%a8-phpword-%e7%94%a2%e7%94%9f-mysql-%e8%b3%87%e6%96%99%e5%ba%ab%e7%b5%90%e6%a7%8b%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=2547","title":{"rendered":"\u4f7f\u7528 PHPWord \u7522\u751f MySQL \u8cc7\u6599\u5eab\u7d50\u69cb\u6587\u4ef6"},"content":{"rendered":"<p>\u958b\u767c\u4e00\u500b\u542b\u8cc7\u6599\u5eab\u7684\u7db2\u7ad9\uff0c\u4e0d\u8ad6\u662f\u500b\u4eba\u8208\u8da3\u6216\u662f\u5de5\u4f5c\u9700\u6c42\uff0c\u4e8b\u5f8c\u7684\u6587\u4ef6\u88fd\u4f5c\u90fd\u662f\u300c\u795e\u7169\u300d\u7684\u3002<\/p>\n<p>\u81f3\u5c11\u6211\u5c31\u4e0d\u559c\u6b61\u53e6\u5916\u5beb\u8cc7\u6599\u7d50\u69cb\u8aaa\u660e\u6587\u4ef6\uff0c\u5c24\u5176\u662f\u4f7f\u7528 phpMyAdmin \u9019\u7a2e GUI \u754c\u9762\u64cd\u4f5c\u8cc7\u6599\u5eab\u5f8c\uff0c\u5c31\u89ba\u5f97\u5982\u679c\u9084\u8981\u82b1\u5f88\u591a\u6642\u9593\u4f86\u505a\u591a\u9918\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u6211\u5c31\u8981\u82b1\u66f4\u591a\u7684\u6642\u9593\u4f86\u5beb\u4e00\u500b\u81ea\u52d5\u7522\u751f\u8cc7\u6599\u5eab\u7d50\u69cb\u6587\u4ef6\u7684\u7a0b\u5f0f ...<\/p>\n<p>\u5927\u81f4\u4e0a\u7684\u60f3\u6cd5\u5c31\u662f\u628a\u6240\u6709\u7684\u8aaa\u660e\u90fd\u76f4\u63a5\u5beb\u5728\u8cc7\u6599\u5eab\u5167\uff0cMySQL \u7684\u8cc7\u6599\u8868\u3001\u6b04\u4f4d\u90fd\u6709 Comment \u6b04\u4f4d\u53ef\u4ee5\u586b\u5beb\uff0cphpMyAdmin \u7684\u9810\u8a2d\u5feb\u901f\u532f\u51fa\u4e5f\u6703\u628a Comment \u532f\u51fa\uff0c\u56e0\u6b64\u5099\u4efd\u4ee5\u53ca\u8aaa\u660e\u53ef\u4ee5\u9054\u6210\u4e00\u81f4\u6027\u540c\u6b65\u3002<\/p>\n<h2>\u5217\u51fa\u8a72\u8cc7\u6599\u5eab\u6240\u6709\u8cc7\u6599\u8868<\/h2>\n<pre class=\"lang:mysql decode:true \">SHOW TABLES<\/pre>\n<p>--<\/p>\n<h2>\u8cc7\u6599\u8868\u8aaa\u660e<\/h2>\n<p>\u53c3\u8003\uff1a\u00a0<a href=\"http:\/\/dba.stackexchange.com\/questions\/59587\/changing-mysql-table-comment\">changing mysql table comment<\/a><\/p>\n<pre class=\"lang:mysql decode:true\">SHOW TABLE STATUS WHERE name='TableName'<\/pre>\n<p>\u4fee\u6539\u8cc7\u6599\u8868\u8aaa\u660e<\/p>\n<pre class=\"lang:mysql decode:true\">ALTER TABLE TableName COMMENT='\u8cc7\u6599\u8868\u8aaa\u660e\\n\u9032\u4e00\u6b65\u8aaa\u660e'<\/pre>\n<p>--<\/p>\n<p>\u986f\u793a\u5b8c\u6574\u7684\u8cc7\u6599\u8868\u6b04\u4f4d\u8cc7\u8a0a<\/p>\n<pre class=\"lang:mysql decode:true\">SHOW FULL FIELDS FROM TableName<\/pre>\n<p>--<\/p>\n<h2>\u4f7f\u7528 PHP \u7522\u51fa\u00a0docx, odt, rtf, HTML \u6587\u4ef6<\/h2>\n<p>\u4f7f\u7528\u5957\u4ef6\u00a0<a href=\"https:\/\/github.com\/PHPOffice\/PHPWord\">PHPWord<\/a>\u00a0\uff0c\u6700\u597d\u7684\u5b78\u7fd2\u65b9\u5f0f\u5c31\u662f\u770b samples code<\/p>\n<p><strong>\u89c0\u770b\u7bc4\u4f8b\u7d50\u679c\u00a0samples\u00a0results<\/strong><\/p>\n<ol>\n<li>\u4e0b\u8f09 PHPWord \u4e26\u89e3\u58d3\u7e2e\u5230\u7db2\u7ad9<\/li>\n<li>\u5c07\u00a0PHPWord-develop\\samples\\<strong>results<\/strong>\u00a0\u76ee\u9304\u4fee\u6539\u70ba\u53ef\u8b80\u5beb\u6b0a\u9650<\/li>\n<li>\u700f\u89bd\u00a0PHPWord-develop\\samples \u4e0b\u62c9\u9078\u64c7\u9805\u76ee\uff0c\u9ede\u9078\u6587\u4ef6\u985e\u5225\u4e0b\u8f09<\/li>\n<\/ol>\n<p>--<\/p>\n<p><strong>\u55ae\u4f4d\u8f49\u63db\u67e5\u8a62<\/strong><\/p>\n<p>PHPWord \u9810\u8a2d\u4f7f\u7528\u7684\u6578\u503c\u55ae\u4f4d\u662f Twip \uff0c\u60f3\u8981\u66f4\u9032\u4e00\u6b65\u4e86\u89e3\u53ef\u4ee5\u53c3\u8003 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Twip\" target=\"_blank\">https:\/\/en.wikipedia.org\/wiki\/Twip<\/a><\/p>\n<p>\u9019\u88e1\u6709\u55ae\u4f4d\u8f49\u63db\uff0c\u53ef\u4ee5\u5728\u6587\u66f8\u7de8\u8f2f\u8edf\u9ad4\u8a2d\u8a08\u5f8c\u53d6\u5f97\u5927\u81f4\u8ddd\u96e2\u5f8c\u518d\u9032\u884c\u63db\u7b97 \u2192\u00a0<a href=\"http:\/\/endmemo.com\/convert\/topography.php\" target=\"_blank\">Topography Conversion<\/a><\/p>\n<p>--<\/p>\n<p><strong>\u8a2d\u5b9a\u9810\u8a2d\u5b57\u578b<\/strong><\/p>\n<p>\u53c3\u8003\u81f3\uff1a<a href=\"https:\/\/phpword.readthedocs.org\/en\/latest\/general.html#default-font\">Default font<\/a><\/p>\n<pre class=\"lang:php decode:true\">$phpWord = new \\PhpOffice\\PhpWord\\PhpWord();\r\n$phpWord-&gt;setDefaultFontSize(11);<\/pre>\n<p>--<\/p>\n<pre class=\"nums:true lang:php decode:true\">&lt;?php\r\n\/**\r\n * Created by PhpStorm.\r\n * User: hoyo\r\n * Date: 2015\/9\/21\r\n * Time: \u4e0b\u5348 02:30\r\n *\/\r\n\r\nnamespace Hoyo\\Front;\r\n\r\nrequire OS_PATH .\"\/Component_Back\/PHPWord-develop\/src\/PhpWord\/Autoloader.php\";\r\nuse PhpOffice\\PhpWord\\Autoloader;\r\nuse PhpOffice\\PhpWord\\Settings;\r\n\r\nAutoloader::register();\r\nSettings::loadConfig();\r\n\r\nclass MySQLStruct\r\n{\r\n    var $TN = 'MJAPP_SoundU'; \/\/ Material DEVELOP TimeIsMoney\r\n    function __construct()\r\n    {\r\n        $init = new \\Hoyo\\Init();\r\n        $this-&gt;init = $init;\r\n        \/\/$this-&gt;db = $init-&gt;PDO();\r\n\r\n        $PDO = new \\PDO(\"mysql:dbname=\". $this-&gt;TN .\";host=192.168.0.101;charset=utf8\", \"root\", \"sly-ha-123\");\r\n        $PDO-&gt;exec(\"set names utf8\"); \/\/ php 5.3.6 \u4e4b\u524d\u7684\u820a\u7248\u672c\r\n        $this-&gt;db = $PDO;\r\n\r\n        $this-&gt;smarty = $init-&gt;smarty();\r\n        $this-&gt;LNG = $GLOBALS['L']['L'];\r\n\r\n        $this-&gt;DefaultPage();\r\n    }\r\n\r\n    function DefaultPage()\r\n    {\r\n\r\n        $phpWord = new \\PhpOffice\\PhpWord\\PhpWord();\r\n        $phpWord-&gt;setDefaultFontSize(11);\r\n        $section = $phpWord-&gt;addSection(\r\n            array('paperSize'=&gt;'A4', 'marginLeft'=&gt;600, 'marginRight'=&gt;600, 'marginTop'=&gt;1100, 'marginBottom'=&gt;1100)\r\n        );\r\n\r\n        $header = array('size' =&gt; 16, 'bold' =&gt; true);\r\n\r\n        $sql = \"SHOW TABLES\";\r\n        $pre = $this-&gt;db-&gt;prepare($sql);\r\n        $pre-&gt;execute();\r\n        while( $row = $pre-&gt;fetch() ) {\r\n            $TableName = $row['Tables_in_'. $this-&gt;TN];\r\n\r\n            \/\/ \u8cc7\u6599\u8868\u8aaa\u660e\r\n            $sql = \" SHOW TABLE STATUS WHERE name='{$TableName}' \" ;\r\n            $preTC = $this-&gt;db-&gt;prepare($sql);\r\n            $preTC-&gt;execute();\r\n            $rowTC = $preTC-&gt;fetch();\r\n            $Comment = explode( \"^\", $rowTC['Comment'] );\r\n            $TableNameComment = array_shift($Comment);\r\n            \/\/$TableComment = $TableNameComment;\r\n            \/\/$section-&gt;addText(htmlspecialchars( $TableComment, ENT_COMPAT, 'UTF-8'));\r\n\r\n            \/\/ \u8cc7\u6599\u8868\u6a19\u984c\r\n            $TableTitle = $TableName;\r\n            if ( strlen($TableNameComment)&gt;0 ) $TableTitle .= ' - '. $TableNameComment;\r\n            $section-&gt;addText(htmlspecialchars( $TableTitle, ENT_COMPAT, 'UTF-8'), $header );\r\n            \/\/ \u8cc7\u6599\u8868\u8aaa\u660e\r\n            if ( strlen($Comment[0]) &gt;0 ) {\r\n                $section-&gt;addText(htmlspecialchars('(' . $Comment[0] . ')', ENT_COMPAT, 'UTF-8'));\r\n            }\r\n\r\n            \/\/ \u8868\u683c\u683c\u73fe\r\n            $styleTable = array('borderSize' =&gt; 6, 'borderColor' =&gt; '006699', 'cellMargin' =&gt; 80);\r\n            \/\/ \u7b2c\u4e00\u884c \u6a19\u984c\u683c\u5f0f\r\n            $styleFirstRow = array('borderBottomSize' =&gt; 18, 'borderBottomColor' =&gt; '0000FF', 'bgColor' =&gt; '66BBFF');\r\n            \/\/ \u5c07\u8868\u683c\u6a19\u984c\u6a23\u5f0f\u52a0\u5165\r\n            $phpWord-&gt;addTableStyle('Fancy Table', $styleTable, $styleFirstRow);\r\n\r\n            \/\/ \u6a19\u984c\u5782\u76f4\u5c0d\u9f4a\r\n            $styleCell = array('valign' =&gt; 'center');\r\n            \/\/ \u6a19\u984c\u6587\u5b57\u7c97\u9ad4 \u6c34\u5e73\u5c0d\u9f4a\r\n            $fontStyle = array('bold' =&gt; true, 'align' =&gt; 'center');\r\n\r\n            $table = $section-&gt;addTable('Fancy Table');\r\n            $table-&gt;addRow(400);\r\n            $table-&gt;addCell(500, $styleCell)-&gt;addText(htmlspecialchars('#', ENT_COMPAT, 'UTF-8'), $fontStyle);\r\n            $table-&gt;addCell(3200, $styleCell)-&gt;addText(htmlspecialchars('\u6b04\u4f4d\u540d\u7a31', ENT_COMPAT, 'UTF-8'));\r\n            $table-&gt;addCell(1400, $styleCell)-&gt;addText(htmlspecialchars('\u578b\u614b', ENT_COMPAT, 'UTF-8'));\r\n            $table-&gt;addCell(1600, $styleCell)-&gt;addText(htmlspecialchars('\u9810\u8a2d\u503c', ENT_COMPAT, 'UTF-8'));\r\n            $table-&gt;addCell(1800, $styleCell)-&gt;addText(htmlspecialchars('\u9375\u503c\u3001\u9644\u52a0', ENT_COMPAT, 'UTF-8'));\r\n            $table-&gt;addCell(2100, $styleCell)-&gt;addText(htmlspecialchars('\u8aaa\u660e', ENT_COMPAT, 'UTF-8'));\r\n\r\n            $i = 1;\r\n            $sql = \" SHOW FULL FIELDS FROM `{$TableName}` \";\r\n            $preTable = $this-&gt;db-&gt;prepare($sql);\r\n            $preTable-&gt;execute();\r\n            while( $rowTable = $preTable-&gt;fetch() ) {\r\n                $table-&gt;addRow();\r\n                $table-&gt;addCell()-&gt;addText(htmlspecialchars($i, ENT_COMPAT, 'UTF-8'));\r\n                $table-&gt;addCell()-&gt;addText(htmlspecialchars($rowTable['Field'], ENT_COMPAT, 'UTF-8'));\r\n                $table-&gt;addCell()-&gt;addText(htmlspecialchars($rowTable['Type'], ENT_COMPAT, 'UTF-8'));\r\n                $table-&gt;addCell()-&gt;addText(htmlspecialchars($rowTable['Default'], ENT_COMPAT, 'UTF-8'));\r\n\r\n                \/\/ Key &amp; Extra \u9700\u8981\u7279\u5225\u8655\u7406\r\n                $KeyExtra = $table-&gt;addCell();\r\n                $Key = htmlspecialchars($rowTable['Key'], ENT_COMPAT, 'UTF-8');\r\n                $Extra = htmlspecialchars($rowTable['Extra'], ENT_COMPAT, 'UTF-8');\r\n                $KeyExtra-&gt;addText($Key);\r\n                $KeyExtra-&gt;addText($Extra);\r\n\r\n                $table-&gt;addCell()-&gt;addText(htmlspecialchars($rowTable['Comment'], ENT_COMPAT, 'UTF-8'));\r\n\r\n                $i++; \/\/ # \u5e8f\u865f \u65b9\u4fbf\u548c phpMyAdmin \u6838\u5c0d\r\n            }\r\n\r\n\r\n            \/\/ \u4e0b\u4e00\u9801 (\u4e00\u500b\u8cc7\u6599\u8868\u4e00\u9801)\r\n            $section-&gt;addPageBreak();\r\n        }\r\n\r\n        \/\/ \u5132\u5b58 Word\r\n        \/\/ Word2007, ODText, HTML\r\n        $phpWord-&gt;save('\/tmp\/'. $this-&gt;TN .'.docx', 'Word2007');\r\n\r\n        $this-&gt;smarty-&gt;assign('LNG', $this-&gt;LNG);\r\n        \/\/echo __CLASS__;\r\n        $this-&gt;smarty-&gt;assign('Content', 'Page\/'.__CLASS__.'.tpl');\r\n        $this-&gt;smarty-&gt;display('Layout_index.tpl');\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<p>\u5b8c\u6210\u54c1<\/p>\n<p><a href=\"http:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2015\/09\/Image-256.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-3050\" src=\"http:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2015\/09\/Image-256-276x300.png\" alt=\"Image 256\" width=\"276\" height=\"300\" srcset=\"https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2015\/09\/Image-256-276x300.png 276w, https:\/\/blog.hoyo.idv.tw\/wp-content\/uploads\/2015\/09\/Image-256.png 700w\" sizes=\"(max-width: 276px) 100vw, 276px\" \/><\/a><\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"2547\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;6,204&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u958b\u767c\u4e00\u500b\u542b\u8cc7\u6599\u5eab\u7684\u7db2\u7ad9\uff0c\u4e0d\u8ad6\u662f...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"2547\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;6,204&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[260],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2547"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2547"}],"version-history":[{"count":9,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2547\/revisions"}],"predecessor-version":[{"id":3051,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2547\/revisions\/3051"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}