{"id":1814,"date":"2012-08-16T20:20:37","date_gmt":"2012-08-16T12:20:37","guid":{"rendered":"http:\/\/kuki.idv.tw\/?p=1814"},"modified":"2012-08-16T20:20:37","modified_gmt":"2012-08-16T12:20:37","slug":"php%e6%8f%9b%e7%ae%97excel%e7%9a%84column%e8%8b%b1%e6%96%87%e8%88%87%e6%95%b8%e5%ad%97%e8%bd%89%e6%8f%9b","status":"publish","type":"post","link":"https:\/\/www.kuki.idv.tw\/?p=1814","title":{"rendered":"php\u63db\u7b97Excel\u7684Column\u82f1\u6587\u8207\u6578\u5b57\u8f49\u63db"},"content":{"rendered":"<p>\u5728\u532f\u5165Excel\u7684\u6642\u5019\uff0c\u56e0\u70ba\u8b80\u53d6\u5230\u7684Col\u70ba\u82f1\u6587\u6a19\u793a\uff0c\u770b\u8d77\u4f86\u50cf\u662f26\u9032\u4f4d\uff0c\u4f46\u662f\u662fA~Z\u4f86\u8868\u793aA=1, B=2,C=3&#8230;.Z=0&#8230;AA=27&#8230;<\/p>\n<p>\u6240\u4ee5\u532f\u5165\u7684\u6642\u5019\uff0c\u8981\u8b80\u884c\u9700\u900f\u904e\u7279\u6b8a\u8f49\u63db<\/p>\n<p>\u5e95\u4e0b\u662f\u6211\u81ea\u5df1\u60f3\u7684\u7a0b\u5f0f\u78bc\uff0c\u5206\u4eab\u7d66\u4f86\u53c3\u8003\u7684\u4eba<\/p>\n<p>&lt;?php<\/p>\n<p>\/\/Test<br \/>\nfor($j=26; $j&lt;=1090; $j=$j+26){<br \/>\n$d = excel_num_to_col($j);<br \/>\necho &#8220;$j&#8221;;<br \/>\nprint_r($d);<br \/>\n}<\/p>\n<p>\/\/\u6578\u5b57\u8f49\u82f1\u6587<br \/>\nfunction excel_num_to_col($num){<br \/>\nfor($i=$num; $i&gt;0; $i=($i%26==0)?intval($i\/26)-1:intval($i\/26)){<br \/>\n$result[] = num_az($i%26);<br \/>\n}<br \/>\nreturn array_reverse($result);<br \/>\n}<\/p>\n<p>\/\/\u82f1\u6587\u8f49\u6578\u5b57<br \/>\nfunction excel_col_to_num($str){<br \/>\n$arr = array_reverse(str_split($str));<br \/>\nforeach((array)$arr as $key =&gt; $val){<br \/>\n$result += pow(26, $key)*az_num($val);<br \/>\n}<br \/>\nreturn $result;<br \/>\n}<\/p>\n<p>\/\/\u82f1\u6587\u8f49\u6578\u5b57\u5c0d\u7167<br \/>\nfunction az_num($str){<br \/>\nif(strtoupper($str)==&#8221;A&#8221;){return 1;}<br \/>\nif(strtoupper($str)==&#8221;B&#8221;){return 2;}<br \/>\nif(strtoupper($str)==&#8221;C&#8221;){return 3;}<br \/>\nif(strtoupper($str)==&#8221;D&#8221;){return 4;}<br \/>\nif(strtoupper($str)==&#8221;E&#8221;){return 5;}<br \/>\nif(strtoupper($str)==&#8221;F&#8221;){return 6;}<br \/>\nif(strtoupper($str)==&#8221;G&#8221;){return 7;}<br \/>\nif(strtoupper($str)==&#8221;H&#8221;){return 8;}<br \/>\nif(strtoupper($str)==&#8221;I&#8221;){return 9;}<br \/>\nif(strtoupper($str)==&#8221;J&#8221;){return 10;}<br \/>\nif(strtoupper($str)==&#8221;K&#8221;){return 11;}<br \/>\nif(strtoupper($str)==&#8221;L&#8221;){return 12;}<br \/>\nif(strtoupper($str)==&#8221;M&#8221;){return 13;}<br \/>\nif(strtoupper($str)==&#8221;N&#8221;){return 14;}<br \/>\nif(strtoupper($str)==&#8221;O&#8221;){return 15;}<br \/>\nif(strtoupper($str)==&#8221;P&#8221;){return 16;}<br \/>\nif(strtoupper($str)==&#8221;Q&#8221;){return 17;}<br \/>\nif(strtoupper($str)==&#8221;R&#8221;){return 18;}<br \/>\nif(strtoupper($str)==&#8221;S&#8221;){return 19;}<br \/>\nif(strtoupper($str)==&#8221;T&#8221;){return 20;}<br \/>\nif(strtoupper($str)==&#8221;U&#8221;){return 21;}<br \/>\nif(strtoupper($str)==&#8221;V&#8221;){return 22;}<br \/>\nif(strtoupper($str)==&#8221;W&#8221;){return 23;}<br \/>\nif(strtoupper($str)==&#8221;X&#8221;){return 24;}<br \/>\nif(strtoupper($str)==&#8221;Y&#8221;){return 25;}<br \/>\nif(strtoupper($str)==&#8221;Z&#8221;){return 26;}<br \/>\n}<\/p>\n<p>\/\/\u6578\u5b57\u8f49\u82f1\u6587\u5c0d\u7167<br \/>\nfunction num_az($num){<br \/>\nif($num==1){return &#8220;A&#8221;;}<br \/>\nif($num==2){return &#8220;B&#8221;;}<br \/>\nif($num==3){return &#8220;C&#8221;;}<br \/>\nif($num==4){return &#8220;D&#8221;;}<br \/>\nif($num==5){return &#8220;E&#8221;;}<br \/>\nif($num==6){return &#8220;F&#8221;;}<br \/>\nif($num==7){return &#8220;G&#8221;;}<br \/>\nif($num==8){return &#8220;H&#8221;;}<br \/>\nif($num==9){return &#8220;I&#8221;;}<br \/>\nif($num==10){return &#8220;J&#8221;;}<br \/>\nif($num==11){return &#8220;K&#8221;;}<br \/>\nif($num==12){return &#8220;L&#8221;;}<br \/>\nif($num==13){return &#8220;M&#8221;;}<br \/>\nif($num==14){return &#8220;N&#8221;;}<br \/>\nif($num==15){return &#8220;O&#8221;;}<br \/>\nif($num==16){return &#8220;P&#8221;;}<br \/>\nif($num==17){return &#8220;Q&#8221;;}<br \/>\nif($num==18){return &#8220;R&#8221;;}<br \/>\nif($num==19){return &#8220;S&#8221;;}<br \/>\nif($num==20){return &#8220;T&#8221;;}<br \/>\nif($num==21){return &#8220;U&#8221;;}<br \/>\nif($num==22){return &#8220;V&#8221;;}<br \/>\nif($num==23){return &#8220;W&#8221;;}<br \/>\nif($num==24){return &#8220;X&#8221;;}<br \/>\nif($num==25){return &#8220;Y&#8221;;}<br \/>\nif($num==0){return &#8220;Z&#8221;;}<br \/>\n}<br \/>\n?&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u532f\u5165Excel\u7684\u6642\u5019\uff0c\u56e0\u70ba\u8b80\u53d6\u5230\u7684Col\u70ba\u82f1\u6587\u6a19\u793a\uff0c\u770b\u8d77\u4f86\u50cf\u662f26\u9032\u4f4d\uff0c\u4f46\u662f\u662fA~Z\u4f86\u8868\u793aA=1, B=2, &hellip; <a href=\"https:\/\/www.kuki.idv.tw\/?p=1814\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008php\u63db\u7b97Excel\u7684Column\u82f1\u6587\u8207\u6578\u5b57\u8f49\u63db\u3009<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1814"}],"collection":[{"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1814"}],"version-history":[{"count":2,"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1814\/revisions"}],"predecessor-version":[{"id":1816,"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/1814\/revisions\/1816"}],"wp:attachment":[{"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kuki.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}