可以任何人請讓我知道,我需要打印/列出按字母順序(A-Z)字符管理Excel單元格。有沒有任何PHP函數列出按字母順序?最好的方式來使用PHP
我需要的結果是
A1
B1
C1
D1
...
...
...
OR
A
B
C
...
...
可以任何人請讓我知道,我需要打印/列出按字母順序(A-Z)字符管理Excel單元格。有沒有任何PHP函數列出按字母順序?最好的方式來使用PHP
我需要的結果是
A1
B1
C1
D1
...
...
...
OR
A
B
C
...
...
你可以這樣做:
foreach (range('A', 'Z') as $char) {
echo $char . "\n";
}
或者:
for ($char = 'A'; $char <= 'Z'; $char++) {
echo $char . "\n";
}
range()
支持,因爲PHP 4.1的信件,所以你可以這樣做:
$azRange = range('A', 'Z');
foreach ($azRange as $letter)
{
print("$letter\n");
}
我認爲你應該使用range function :
$a=range("A","Z");
foreach($a as $char)
echo $char."\n";
此:
$range = range("A", "Z");
for ($i=1; i<=100; i++) {
foreach ($range as $letter) {
print("$letter$i\n");
}
}
將打印你的所有組合:
A1
B1
C1
... ...
... ...
V100
W100
Z100
根據您的需要修改範圍。
如果你正在尋找一個全面的Excel功能,然後看看PHPExcel它提供了很多方法用於處理單元格地址和範圍,以及Excel和其他各種電子表格文件格式的讀取/寫入
這裏是我使用PHP代碼的HTML代碼,正常工作
for($i = 'a' ; $i <= 'z' ; $i++){
echo $i. "<br />"; }
相信它與否對我來說實際上是有用的,因爲我需要像在這裏一樣將字母加1。謝謝! – 2014-02-13 15:58:54
你也可以這樣做:在這裏使用ASCII範圍。
for($i = 65 ; $i<=90; $i++)
{
echo chr($i);
}
此代碼用於顯示A,B,...,ZY,ZZ。
function print_char($end_no=90, $start_no=65, $prefix_no=0)
{ $vasant='';
if($prefix_no==0)
{
for($set=$start_no; $set<=$end_no; $set++)
{
$vasant.=(chr($prefix_no).chr($set)).', ';
}
}
else
{
for($set=$start_no; $set<=90; $set++)
{
$vasant.=(chr($set)).', ';
}
for($pre_loop=65; $pre_loop<=$prefix_no; $pre_loop++)
{
for($set=$start_no; $set<=90; $set++)
{
if($set>=$end_no && $pre_loop==$prefix_no)
{
$vasant.=(chr($pre_loop).chr($set)).'. ';
break;
}
else
{
$vasant.=(chr($pre_loop).chr($set)).', ';
}
}
}
}
return $vasant;
}
$show=print_char(90,65,90);
echo $show;
此代碼會導致您的要求....
<?php
$x= 'A';
for($i=0;$i<26;$i++)
{
echo $x."<br/>";//generates A,B,C,D...Z
$x++;
if($i == 25)
{
$x = 'A';
$y = '1';
for($j=0;$j<26;$j++)
{
echo $x.$y."<br />";//generates A1,B1...Z1
$x++;
if($j == 25)
{
$x = 'A';
$y++;
for($k=0;$k<26;$k++)
{
echo $x.$y."<br />";//generates A2,B2....Z2
$x++;
}
}
}
}
}
?>
$len = 0;
for ($char = 'A'; $char <= 'Z'; $char++) {
$len++;
if ($len == 26) {
break;
}
echo $char;
}
雖然此代碼片段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – andreas 2016-10-31 09:32:26
**標記/評論者:** [僅限代碼解答,例如downvote,請勿刪除!](// meta.stackoverflow.com/a/260413/2747593) – 2016-10-31 14:34:57
對於Excel表
使用此遞歸函數來從A得到確切範圍AZ
function myRange($end_column = '', $first_letters = '') {
$columns = array();
$length = strlen($end_column);
$letters = range('A', 'Z');
// Iterate over 26 letters.
foreach ($letters as $letter) {
// Paste the $first_letters before the next.
$column = $first_letters . $letter;
// Add the column to the final array.
$columns[] = $column;
// If it was the end column that was added, return the columns.
if ($column == $end_column)
return $columns;
}
// Add the column children.
foreach ($columns as $column) {
// Don't itterate if the $end_column was already set in a previous itteration.
// Stop iterating if you've reached the maximum character length.
if (!in_array($end_column, $columns) && strlen($column) < $length) {
$new_columns = myRange($end_column, $column);
// Merge the new columns which were created with the final columns array.
$columns = array_merge($columns, $new_columns);
}
}
return $columns;
}
如呼叫功能。
print_r(myRange('AZ'));
會給你造成
一個 乙 Ç 。 。 。 AX AY AZ
這有可能超過Z.更多這就是A,B,...,Z,AA,AB,AC,... – 2016-01-07 07:44:01
@VeckHsiao只需使用隔行掃描循環。 – 2017-08-01 06:53:08