定制 glider88/relative-coordinates 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

glider88/relative-coordinates

最新稳定版本:1.0.1

Composer 安装命令:

composer require glider88/relative-coordinates

包简介

Plugin for PhpSpreadsheet, add relative coordinates transformer

README 文档

README

Abstraction for PhpSpreadsheet, add relative coordinate transformer.

Installation:

composer require glider88/relative-coordinates

Start:

bin/re  # first run
bin/up  # start app
bin/unit # run tests

The core idea is to define area with relative sub coordinates. This allows you to define a table template and use it in many places in an Excel document. Also, you can easily add, remove, swap columns without affecting the rest of the sheet.

$coordT = RelativeCoordinates::new('B3', ['one', 'two', 'three']);

If you need formulas in Excel:

$dataT = new RelativeData($coordT);

Might be useful, class for easy selection of columns and rows:

$positional = new PositionalCoordinates($columns, $height);

$firstColumn = $positional->relativeColumn(1);
$lastRow = $positional->relativeRow(-1);

Table template:

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use Glider88\RelativeCoordinates\Relative\RelativeCoordinates;
use Glider88\RelativeCoordinates\Relative\RelativeData;
use PhpOffice\PhpSpreadsheet\Style\Fill;

$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();

$start = 'B3';
$avg = static fn(string $color) => "=AVERAGE({{{$color}2:{$color}4}})";
$data = [
    ['Color', 'Red', 'Green', 'Blue'],
    ['yellow',  255, 255,   0],
    ['cyan',      0, 255, 255],
    ['magenta', 255,   0, 255],
    ['Average color', $avg('red'), $avg('green'), $avg('blue')]
];

$coordT = RelativeCoordinates::new($start, ['color', 'red', 'green', 'blue']);
$dataT = new RelativeData($coordT);

// table styles
$worksheet
    ->getStyle($coordT->absolute('color1:blue1'))
    ->getFont()
    ->setBold(true);

$worksheet
    ->getStyle($coordT->absolute('color1:blue1'))
    ->getFill()
    ->setFillType(Fill::FILL_SOLID)
    ->getStartColor()
    ->setARGB('509965');

$worksheet
    ->getStyle($coordT->absolute('color5:blue5'))
    ->getFill()
    ->setFillType(Fill::FILL_SOLID)
    ->getStartColor()
    ->setARGB('81a8f0');
// end styles

$worksheet->fromArray($dataT->absolute($data), null, $start);

$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('table.xls');

More complex example: example/Table.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-08