PHP code example of asharma327 / apispreadsheets-php

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

    

asharma327 / apispreadsheets-php example snippets




use ApiSpreadsheets\Spreadsheet;

// Data can have 3 formats:
$data = [ 
    'Id' => 1,
    'Name' => 'AT&T'
];

// Or:
$data = [[
    'Id' => 1,
    'Name' => 'AT&T'
], [
    'Id' => 2,
    'Name' => 'Apple'
]];

// Or:
$data = [
    'Id' => [1, 2],
    'Name' => ['AT&T', 'Apple']
];

$response = Spreadsheet::create('fileId', $data);

// Or if the file is private you can provide API keys as extra parameters:
$response = Spreadsheet::create('fileId', $data, 'accessKey', 'secretKey');

// ['message' => 'Your rows were created successfully', 'status_code' => 201]



use ApiSpreadsheets\Spreadsheet;

$data = [ 
    'Id' => 1,
    'Name' => 'AT&T'
];

$query = "select*from[fileId]whereId=1";

$response = Spreadsheet::update('fileId', $data, $query);

// Or if the file is private you can provide API keys as extra parameters:
$response = Spreadsheet::update('fileId', $data, $query, 'accessKey', 'secretKey');

// ['message' => 'Your rows were updated successfully', 'status_code' => 201]



use ApiSpreadsheets\Spreadsheet;

// An optional array to filter or change how the returned rows look like
$params = [ 
    'dataFormat' => 'column', // Can be matrix or column, the default is row.
    'limit' => 10, // limit the returned rows
    'count' => true, // only return the count of the result
    'query' => "select*from{$file_id}whereId=1" // SQL style query to get a subset of rows.
];

$response = Spreadsheet::read('fileId', $params);

// Or if the file is private you can provide API keys as extra parameters:
$response = Spreadsheet::read('fileId', $params, 'accessKey', 'secretKey');

// Response:

// in case of dataFormat is row (default):
// ['data' => [['Id' => 1, 'Name' => 'Apple'], [...]], 'status_code' => 200]

// column dataFormat:
// ['Id' => [1, ...], 'Name' => ['Apple', ...], 'status_code' => 200]

// matrix dataFormat:
// ['data' => [[1, 'Apple'], [...]], 'status_code' => 200]

// In case of count is true
// ['count' => 10, 'status_code' => 200]



use ApiSpreadsheets\Spreadsheet;

$query = "delete*from[fileID]whereId=1";

$response = Spreadsheet::delete('fileId', $query);

// Or if the file is private you can provide API keys as extra parameters:
$response = Spreadsheet::delete('fileId', $query, 'accessKey', 'secretKey');


// ['message' => '2 rows were deleted', 'status_code' => 200]

['error' = 'Error message', 'status_code' => 400]

composer