Giter Club home page Giter Club logo

simple-google-sheets's Introduction

Google Sheets

GoogleSheet

GoogleSheet is a convenient wrapper for the standard google/apiclient package, providing an easy-to-use interface for working with Google Sheets.

Installation

Require the package using Composer:

composer require lozemc/simple-google-sheets

Usage

Creating an Instance

use Lozemc\GoogleSheet;

// Replace 'your_table_id' and 'path/to/your/credentials-config.json' with actual values

$table_id = 'your_table_id';
$credentials = 'path/to/your/credentials-config.json';

$table = new GoogleSheet($table_id, $credentials);

Setting the Sheet

$table->set_sheet('YourSheetName');

Getting Rows

// Get all rows
$rows = $table->get_rows();

print_r($rows);

// [
//    [ 'A1 value', 'B1 value', 'C1 value' ],
//    [ 'A2 value', 'B2 value', 'C2 value' ],
//    [ 'A3 value', 'B3 value', 'C3 value' ]
// ]


// Get rows from a specific range
$range = 'B2:C3';
$rows = $table->get_rows($range);

print_r($rows);

// [
//    [ 'B2 value', 'C2 value' ],
//    [ 'B3 value', 'C3 value' ]
// ]

Updating Rows

$table->update([['A1 value', 'B1 value']]);

// 

$range = 'A4';
$table->update([['A4 value', 'B4 value']], $range);

// 

$table->update([
    ['A1 value', 'B1 value'],
    ['A2 value', 'B2 value', 'C3 value'],
    ['A3 value', 'B3 value', '', 'D4 value'],
]);

Appending Rows

$table->append([['Value 1', 'Value 2']]);

//

$table->append([['Value 1', 'Value 2']], 'A10');

Simple Example

require_once __DIR__ . '/vendor/autoload.php';

use Lozemc\GoogleSheet;

$table_id = '1gncMRlsonFj2YzYw79QnfVA4Go5UcYkmfgG1T7Vb5Q';
$credentials = __DIR__ . '/credentials-config.json'; 

$table = new GoogleSheet($table_id, $credentials);


// Set the sheet name if not provided during initialization
$table->set_sheet('Sheet1');


// Append new rows
$table->append([
    ['Lisa', 'Anderson'],
    ['Jane', 'Jones'],
]);


// Get all rows
$rows = $table->get_rows();

// Display the retrieved rows
print_r($rows);


// Get rows from a specific range in another sheet
$rows = $table->set_sheet('Sheet2')->get_rows('B10:C20');

print_r($rows);


// Update data in a specific range
$table->update([['New value']], 'B10');
$row = $table->get_rows('B10');

print_r($row);

Requirements

  • PHP >=7.4.33

Dependencies

License

This package is licensed under the MIT License.

simple-google-sheets's People

Contributors

lozemc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.