You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
825 B
PHTML
28 lines
825 B
PHTML
2 years ago
|
<?php
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Helper;
|
||
|
|
||
|
class Excel
|
||
|
{
|
||
|
public static function getColumnKey($index)
|
||
|
{
|
||
|
if ($index >= 256) {
|
||
|
throw new \Exception('Too much Excel column!');
|
||
|
}
|
||
|
$keys = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||
|
if ($index < 26) {
|
||
|
return $keys[$index];
|
||
|
} else {
|
||
|
$first = $index/26;
|
||
|
$second = $index%26;
|
||
|
return $keys[$first-1] . $keys[$second];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static function generateUniqueCode(array $params, string $identity, $length = 8)
|
||
|
{
|
||
|
$md5Code = md5(microtime(true) . json_encode($params) . $identity . rand(0, 9999));
|
||
|
return substr($md5Code, 0, $length);
|
||
|
}
|
||
|
}
|