PHP code example of wpdev / odata-feed

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

    

wpdev / odata-feed example snippets


use PhpOffice\PhpSpreadsheet\Spreadsheet;
use WPDev\ODataFeed\Feed\FeedConfig;
use WPDev\ODataFeed\Writer\LiveXlsxWriter;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Sales');
$sheet->fromArray(['Product', 'Amount'], null, 'A1');
$sheet->fromArray(['Widget', 10], null, 'A2');

$writer = new LiveXlsxWriter($spreadsheet);
$writer->setFeed(new FeedConfig(
    'https://api.example.com/odata',  // OData base URL
    'abc123',                          // feed id (path segment)
    'Sales'                            // entity set / sheet name
));
$writer->save('output.xlsx');

$writer = LiveXlsxWriter::fromFile('/path/to/workbook.xlsx');
$writer->setFeed(new FeedConfig('https://api.example.com/odata', 'abc123', 'Sales'));
$writer->write('output.xlsx');

use WPDev\ODataFeed\Repository\InMemoryFeedRepository;

$repo = new InMemoryFeedRepository();
$writer = new LiveXlsxWriter($spreadsheet, $repo);
$writer->setFeed($config);
$writer->write('output.xlsx');

$meta = $repo->find('abc123');
bash
php examples/example-1/build.php
bash
cd examples/example-2
composer install
php playground.php --build
php -S localhost:8080 playground.php

{rtrim(baseUrl, '/')}/{feedId}/{entitySet}