承接 malenki/coord2coord 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

malenki/coord2coord

最新稳定版本:1.2.0

Composer 安装命令:

composer require malenki/coord2coord

包简介

Convert spreadsheet coordinate to numeric coordinates and vice versa

README 文档

README

Convert spreadsheet columns coordinates to numeric coordinates and reverse too

Why?

Sometimes, when you develop some code about some CSV or something like that, you have reference given by some people using spreadsheet value (column A, AA, Z…) or index value (1, 2, 3) or even index value starting to zero (0, 1, 2…).

So, this little library deals with that. So, you can easily switch from one system to another.

How?

You can play with it using two ways:

  • By using library to use it into your code
  • By using CLI script available.

Using the library

Very simple, install it using composer. You can find it on https://packagist.org/packages/malenki/coord2coord.

Quick example converting spreadsheet column name to index starting from one:

use \Malenki\Coord2Coord;

$c2c = new Coord2Coord();
echo $c2c->l2d('A'); // 1
echo $c2c->l2d('Z'); // 26
echo $c2c->l2d('AA'); // 27

Now the same with index starting from zero (note the constructor's call):

use \Malenki\Coord2Coord;

$c2c = new Coord2Coord(true);
echo $c2c->l2d('A'); // 0
echo $c2c->l2d('Z'); // 25
echo $c2c->l2d('AA'); // 26

Example to show how to convert index to spreadsheet column name:

use \Malenki\Coord2Coord;

$c2c = new Coord2Coord();
echo $c2c->d2l(1); // 'A'
echo $c2c->d2l(26); // 'Z'
echo $c2c->d2l(27); // 'AA'

Again, we can also use starting point as zero:

use \Malenki\Coord2Coord;

$c2c = new Coord2Coord(true);
echo $c2c->d2l(0); // 'A'
echo $c2c->d2l(25); // 'Z'
echo $c2c->d2l(26); // 'AA'

You can also magically convert integer to letters or the reverse:

use \Malenki\Coord2Coord;

$c2c = new Coord2Coord();
echo $c2c->magic(1); // 'A'
echo $c2c->magic('A'); // 1

That's all to know!

But you must also know that if you use incorrect value for index (negative integer, non integer, or zero when starting point is one) then this raises an exception (InvalidArgumentException is it is not an integer or OutOfRangeException for other cases).

Also, if you use any other value than ASCII characters a-zA-Z for convert spreadsheet column name to index then an InvalidArgumentException occurs.

Using CLI script

Again, install it using composer, then, composer install into root directory of sources.

A script is available into bin\coord2coord.

Other way is to use PHAR file, so, just download it or create it using box by doing box build into the root of sources.

Play with it is very simple:

bin\coord2coord --help #display help message
bin\coord2coord A Z AA 56 2
"A" => 1
"Z" => 26
"AA" => 27
"56" => BD
"2" => B
 bin/coord2coord --zero A Z AA 56 2
"A" => 0
"Z" => 25
"AA" => 26
"56" => BE
"2" => C

Simple, isn't it?

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-15