excel的列生成算法
echo '<pre>'; $i = 1; while($i < 703){ $char1 = floor($i / 26); $char2 = $i % 26; if($i % 26 == 0)$char1--; if($i > 1 && $i % 26 == 1) echo '<br/>'; if($char2 == 0) $char2 = 26; if($i <= 26){ echo ' '.chr(64 + $char2). ' '; }else{ echo chr(64 + $char1) . chr(64 + $char2) . ' '; } $i++; } echo '</pre>';
/** * 根据当前列号,返回列字符 * @param int $i * @return string */ function get_excel_row_name($i){ $char1 = floor($i / 26); $char2 = $i % 26; if($i % 26 == 0) $char1--; if($char2 == 0) $char2 = 26; if($i <= 26){ return chr(64 + $char2); }else{ return chr(64 + $char1) . chr(64 + $char2); } }