PHP code example of osmaviation / spreadsheet

1. Go to this page and download the library: Download osmaviation/spreadsheet 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/ */

    

osmaviation / spreadsheet example snippets


$filename = 'my-filename.xlsx';

resolve('spreadsheet')->create($filename, function ($excel) {
    $excel->sheet('Worksheet', function ($sheet) {
        $sheet->fromArray([
            'Foo',
            'Bar',
        ], null, 'A1', true, false);
    });
});

use OSMAviation\Spreadsheet\Facades\Spreadsheet;

$filename = 'my-filename.xlsx';

Spreadsheet::create($filename, function ($excel) {
    $excel->sheet('Worksheet', function ($sheet) {
        $sheet->fromArray([
            'Foo',
            'Bar',
        ], null, 'A1', true, false);
    });
});

use OSMAviation\Spreadsheet\PhpSpreadsheet as Spreadsheet;

class MyController 
{
    public function store(Spreadsheet $spreadsheet)
    {
        $filename = 'my-filename.xlsx';
        
        $spreadsheet->create($filename, function ($excel) {
            $excel->sheet('Worksheet', function ($sheet) {
                $sheet->fromArray([
                    'Foo',
                    'Bar',
                ], null, 'A1', true, false);
            });
        });
    }
}

$filename = 'some-folder/my-filename.xlsx';

Spreadsheet::create($filename, function ($excel) {
    $excel->sheet('Worksheet', function ($sheet) { 
        // $sheet will be a PhpOffice\PhpSpreadsheet\Worksheet\Worksheet instance
        $sheet->fromArray([
            'Foo',
            'Bar',
        ], null, 'A1', true, false);
    });
})->store('local');

Spreadsheet::load($filename, function ($excel) {
    $excel->sheet('Some existing sheet', function($sheet) {
        //
    });
});

Spreadsheet::load($filename, 's3', function ($excel) {
    $excel->sheet('Some sheet', function($sheet) {
        //
    });
});

Spreadsheet::create($filename, function ($excel) {
    $vendorSheet = $excel->getSpreadsheet(); // returns a PhpOffice\PhpSpreadsheet\Spreadsheet instance
})->store('local');