PHP code example of glider88 / relative-coordinates

1. Go to this page and download the library: Download glider88/relative-coordinates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glider88 / relative-coordinates example snippets


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

$dataT = new RelativeData($coordT);

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

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

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');