{"id":1692,"date":"2015-08-11T16:34:25","date_gmt":"2015-08-11T08:34:25","guid":{"rendered":"http:\/\/www.aoisnow.net\/blog\/?p=1692"},"modified":"2015-08-11T16:34:25","modified_gmt":"2015-08-11T08:34:25","slug":"day-9805-%e7%9c%8b%e4%bc%bc%e5%a5%bd%e7%94%a8%e7%9a%84php%e5%ad%97%e6%af%8d%e5%be%aa%e7%8e%af","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/1692","title":{"rendered":"Day 3479 \u770b\u4f3c\u597d\u7528\u7684PHP\u5b57\u6bcd\u5faa\u73af"},"content":{"rendered":"<p>\u6700\u8fd1\u7ed9\u5355\u4f4d\u5199\u4e86\u4e00\u4e2a\u5185\u7f51\u7528\u7684\u5de5\u8d44\u6761\u67e5\u8be2\u9875\u9762\uff0c\u7ed3\u6784\u5f88\u7b80\u5355\uff1a\u8d22\u52a1\u4eba\u5458\u5c06\u4ece\u96c6\u56e2\u8d22\u52a1\u7cfb\u7edf\u4e2d\u5bfc\u51fa\u7684Excel\u8868\u683c\u4e0a\u4f20\uff0c\u5904\u7406\u540e\u4e3a\u6bcf\u4f4d\u5458\u5de5\u5efa\u7acb\u8d26\u6237\uff08\u5f53\u7136\u5df2\u5b58\u5728\u7684\u4e0d\u4f1a\u91cd\u5efa\uff0c\u91cd\u540d\u7684\u4e5f\u6709\u5904\u7406\u65b9\u6848\uff0c\u56e0\u4e3a\u548c\u4e3b\u9898\u65e0\u5173\u4e0d\u8be6\u7ec6\u5c55\u5f00\uff09\uff0c\u5efa\u7acb\u5bf9\u5e94\u5e74\u6708\u6570\u636e\u8868\u5e76\u586b\u5145\u6570\u636e\uff0c\u5458\u5de5\u4f7f\u7528\u8d26\u53f7\u5bc6\u7801\u767b\u5f55\u540e\u53ef\u67e5\u770b\u81ea\u5df1\u7684\u300c\u7535\u5b50\u5de5\u8d44\u6761\u300d\u3002\u505a\u8fd9\u4e2a\u4e1c\u897f\u7684\u521d\u8877\u636e\u8bf4\u662f\u8d22\u52a1\u4e0d\u613f\u610f\u6253\u5370\u7eb8\u8d28\u5de5\u8d44\u6761\u4e86\uff0cft\u3002<\/p>\n<p>\u6574\u5957\u7a0b\u5e8f\u4e2d\u5176\u4ed6\u90e8\u5206\u90fd\u662f\u57fa\u672c\u7684PHP+MySQL\u6d41\u7a0b\uff0c\u552f\u72ec\u5982\u4f55\u5bf9Excel\u8868\u5904\u7406\u662f\u4e2a\u96be\u70b9\uff0c\u5fc5\u987b\u8981\u611f\u8c22PHPExcel\uff0c\u4f7f\u5f97\u8bfb\u53d6Excel\u8868\u683c\u4e0d\u518d\u662f\u6700\u56f0\u96be\u7684\u90e8\u5206\u3002\u5728\u7f16\u5199\u8868\u683c\u8bfb\u53d6\u4ee3\u7801\u7684\u8fc7\u7a0b\u4e2d\uff0c\u8fd8\u53d1\u73b0\u4e86PHP\u4e00\u4e2a\u6709\u8da3\u7684\u7279\u6027\uff1a<\/p>\n<blockquote><p>\u3000\u3000\u5728\u5904\u7406\u5b57\u7b26\u53d8\u91cf\u7684\u7b97\u6570\u8fd0\u7b97\u65f6\uff0cPHP \u6cbf\u88ad\u4e86 Perl \u7684\u4e60\u60ef\uff0c\u800c\u975e C \u7684\u3002\u4f8b\u5982\uff0c\u5728 Perl \u4e2d $a = &#8216;Z&#8217;; $a++; \u5c06\u628a $a \u53d8\u6210&#8217;AA&#8217;\uff0c\u800c\u5728 C \u4e2d\uff0ca = &#8216;Z&#8217;; a++; \u5c06\u628a a \u53d8\u6210 &#8216;[&#8216;\uff08&#8217;Z&#8217; \u7684 ASCII \u503c\u662f 90\uff0c'[&#8216; \u7684 ASCII \u503c\u662f 91\uff09\u3002\u6ce8\u610f\u5b57\u7b26\u53d8\u91cf\u53ea\u80fd\u9012\u589e\uff0c\u4e0d\u80fd\u9012\u51cf\uff0c\u5e76\u4e14\u53ea\u652f\u6301\u7eaf\u5b57\u6bcd\uff08a-z \u548c A-Z\uff09\u3002\u9012\u589e\uff0f\u9012\u51cf\u5176\u4ed6\u5b57\u7b26\u53d8\u91cf\u5219\u65e0\u6548\uff0c\u539f\u5b57\u7b26\u4e32\u6ca1\u6709\u53d8\u5316\u3002<\/p>\n<p style=\"text-align: right;\">\u2014\u2014PHP\u6587\u6863<a href=\"https:\/\/secure.php.net\/manual\/zh\/language.operators.increment.php\" target=\"_blank\">\u300a\u9012\u589e\/\u9012\u51cf\u8fd0\u7b97\u7b26\u300b<\/a><\/p>\n<\/blockquote>\n<p style=\"text-align: left;\">\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u8981\u4ee5\u5217\u4e3a\u5355\u4f4d\u9012\u589e\u8bfb\u53d6\u8868\u683c\u4e2d\u7684\u5185\u5bb9\uff0c\u65e0\u9700\u624b\u5de5\u7f16\u5199\u4ee3\u7801\u5904\u7406\u5217\u540d\u79f0\uff08Excel\u7684\u5217\u540d\u79f0\u662fA\u3001B\u3001C\u2026\u2026AA\u3001AB\u3001AC\u2026\u2026XFD\u4e4b\u7c7b\uff0c\u4e0d\u540c\u7248\u672c\u7684Excel\u672b\u5217\u540d\u79f0\u4e0d\u540c\uff0c\u4f46\u90fd\u662f1-3\u4e2a\u5b57\u6bcd\u7684\u987a\u5e8f\u7ec4\u5408\uff09\uff0c\u53ea\u9700\u8981\u4f7f\u7528\u7c7b\u4f3c\u4e0b\u9762\u7684\u4ee3\u7801\u5373\u53ef\uff1a<\/p>\n<pre><code class=\"language-php\">\u2026\u2026\nfor($col = 'A'; $col &lt; 'ZZ'; $col++) {\n$phpExcel_Sheet -&gt; getCell($col.$row);\n}\n\u2026\u2026\n<\/code><\/pre>\n<p style=\"text-align: left;\">\u4e00\u756a\u52aa\u529b\u540e\uff0c\u7a0b\u5e8f\u5df2\u53ef\u4ee5\u6b63\u786e\u5904\u7406\u8d22\u52a1\u90e8\u65e9\u5148\u7ed9\u51fa\u7684\u6837\u8868\uff0c\u4f46\u662f\u7531\u4e8e\u672c\u5355\u4f4d\u7684\u7279\u6b8a\u60c5\u51b5\uff0c\u8fd8\u6709\u53e6\u4e00\u5957\u5de5\u8d44\u8868\u8981\u5904\u7406\uff0c\u8fd9\u4e2a\u7248\u672c\u7684\u5de5\u8d44\u8868\u683c\u5f0f\u4e0a\u4e0e\u5148\u524d\u7684\u6837\u8868\u65e0\u5f02\uff0c\u53ea\u662f\u5de5\u8d44\u9879\u76ee\u6bd4\u8f83\u591a\uff0c\u5373\uff1a\u5148\u524d\u7684\u6837\u8868\u6700\u5927\u5230Z\u5217\uff0c\u800c\u53e6\u4e00\u7248\u672c\u7684\u6700\u5927\u5217\u4e3aAW\u3002<\/p>\n<p style=\"text-align: left;\">\u7531\u4e8ePHP\u6ca1\u6709\u7b80\u4fbf\u7684\u65b9\u5f0f\u5c06\u5173\u8054\u6570\u7ec4\u6309\u7d22\u5f15\u8fdb\u884c\u8bfb\u53d6\uff08\u8bdd\u8bf4\u4e3a\u5565\u4e0d\u652f\u6301\uff1f\uff09\uff0c\u7a0b\u5e8f\u4e2d\u62fc\u5408\u6700\u7ec8\u5165\u5e93\u7684\u6570\u636e\u65f6\u662f\u8fd9\u6837\u5904\u7406\u7684\uff1a<\/p>\n<pre><code class=\"language-php\">\u2026\u2026\n$lastcol = array_keys($xls_itemname)[sizeof($gz_itemname)-1]; \/\/\u83b7\u53d6\u672b\u5217Key\nforeach($xls_data as $data_row) {\nfor($col = 'E'; $col &lt; $lastcol; $col++) {\n$json_array[$xls_itemname[$col]] = $data_row[$col]; \/\/\u4e3a\u751f\u6210\u7c7b\u4f3c {'\u57fa\u672c\u5de5\u8d44':'800.00', '\u5c97\u4f4d\u85aa\u916c':'1000.00',...}\u8fd9\u6837\u7684JSON\u505a\u51c6\u5907\n}\n$json = json_encode($json_array);\n\u2026\u2026\n}\n\u2026\u2026\n<\/code><\/pre>\n<p style=\"text-align: left;\">\u7ed3\u679c\uff0c\u4ee5\u4e0a\u4ee3\u7801\u5728\u5904\u7406\u7b2c\u4e00\u6279\u6837\u8868\uff08\u672b\u5217\u4e3aZ\uff09\u65f6\u5de5\u4f5c\u826f\u597d\uff1b\u4f46\u5230\u4e86\u7b2c\u4e8c\u6279\u6837\u8868\uff0c\u4e0a\u4f20\u540e\u76f4\u63a5\u8fd0\u884c\u8d85\u65f6\uff0c\u5c06debug\u4fe1\u606f\u6253\u5370\u51fa\u6765\uff0c\u53d1\u73b0\u867d\u7136$lastcol\u7684\u503c\u6b63\u786e\u53d6\u5230\u4e86AW\uff0c\u4f46\u7a0b\u5e8f\u5728\u5904\u7406\u5230AW\u5217\u540e\u5e76\u672a\u505c\u6b62\uff0c\u4e00\u8def\u98d9\u5230\u4e86\u4e0d\u77e5\u9053\u54ea\u91cc\u53bb\uff0c\u76f4\u5230\u8fbe\u5230PHP\u7684\u6700\u5927\u8fd0\u884c\u65f6\u95f4\u88ab\u6390\u65ad\u4e3a\u6b62\u3002<\/p>\n<p style=\"text-align: left;\">\u8c03\u8bd5\u4e86\u5f88\u4e45\u90fd\u4e0d\u77e5\u6240\u63aa\uff0c\u6700\u540e\u53ea\u597d\u7528\u53e6\u4e00\u79cd\u65b9\u5f0f\u8fdb\u884c\u4e34\u65f6\u8865\u6551\uff1a<\/p>\n<pre><code class=\"language-php\">\u2026\u2026\n\/\/\u4e0d\u518d\u53d6$lastcol\nforeach($xls_data as $data_row) {\nfor($col = 'E'; $col &lt; 'ZZ'; $col++) {\nif(isset($xls_itemname[$col]) == FALSE) break; \/\/\u5f53\u53d6\u5230\u672a\u5b9a\u4e49\u7684\u5217\u540d\u65f6\u8df3\u51fa\n\u2026\u2026\n}\n}\n\u2026\u2026\n<\/code><\/pre>\n<p style=\"text-align: left;\">\u8fd9\u79cd\u65b9\u6cd5\u7684\u8fd0\u884c\u6548\u7387\u60f3\u5fc5\u6bd4\u8f83\u4f4e\uff0c\u4f46\u662f\u81f3\u5c11\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p style=\"text-align: left;\">\u731c\u6d4b\u4e0ePHP\u7279\u6b8a\u7684\u5b57\u6bcd\u9012\u589e\u8fd0\u7b97\u7684\u5b9e\u73b0\u6709\u5173\u7cfb\uff0c\u4f46\u662f\u6211\u8fd8\u662f\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u7ed9\u5355\u4f4d\u5199\u4e86\u4e00\u4e2a\u5185\u7f51\u7528\u7684\u5de5\u8d44\u6761\u67e5\u8be2\u9875\u9762\uff0c\u7ed3\u6784\u5f88\u7b80\u5355\uff1a\u8d22\u52a1\u4eba\u5458\u5c06\u4ece\u96c6\u56e2\u8d22\u52a1\u7cfb\u7edf\u4e2d\u5bfc\u51fa\u7684Excel\u8868\u683c\u4e0a\u4f20\uff0c\u5904\u7406 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1692","post","type-post","status-publish","format-standard","hentry","category-sketch"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/1692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=1692"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/1692\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=1692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=1692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=1692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}