Giter Club home page Giter Club logo

sheetfu's Introduction

Sheetfu

https://travis-ci.org/socialpoint-labs/sheetfu.svg?branch=master

Sheetfu was built to interacts with Google Sheets with a simple, intuitive, and fast API. The primary goal of this library is to adapt the Google App Script API for spreadsheets, to Python. With Sheetfu, you can easily get or set cell values, background colors, font colors or any other cell attributes.

Installing

Install and update using pip:

pip install -U Sheetfu

A Simple Example

from sheetfu import SpreadsheetApp

spreadsheet = SpreadsheetApp('path/to/secret.json').open_by_id('<insert spreadsheet id here>')
# if ENV vars are defined, you can do initialize it with:
# spreadsheet = SpreadsheetApp(from_env=True).open_by_id('<insert spreadsheet id here>')

sheet = spreadsheet.get_sheet_by_name('Sheet1')
data_range = sheet.get_data_range()           # returns the sheet range that contains data values.

# this is how you get things
values = data_range.get_values()              # returns a 2D matrix of values.
backgrounds = data_range.get_backgrounds()    # returns a 2D matrix of background colors in hex format.

# this is how you set things
data_range.set_background('#000000')          # set every cell backgrounds to black
data_range.set_font_color('#ffffff')          # set every cell font colors to white

data_range.commit()                           # to commit your changes otherwise nothing gets changed.

To obtain your secret json file and know more about how to initialize your ENV vars, you can refer to the authentication tutorial.

You can refer to the sheetfu API documentation for a more detailed description.

The Table module

Sheetfu also contains a table module that abstracts completely the coordinates system for an ORM-like syntax. The example below is for a sheet with the 3 columns 'name', 'surname' and 'age'.

from sheetfu import Table

spreadsheet = SpreadsheetApp('path/to/secret.json').open_by_id('<insert spreadsheet id here>')
# if ENV vars are defined, you can do initialize it with:
# spreadsheet = SpreadsheetApp(from_env=True).open_by_id('<insert spreadsheet id here>')

data_range = spreadsheet.get_sheet_by_name('people').get_data_range()

table = Table(data_range, backgrounds=True)

for item in table:
    if item.get_field_value('name') == 'foo':
        item.set_field_value('surname', 'bar')              # this set the surname field value
    age = item.get_field_value('age')
    item.set_field_value('age', age + 1)
    item.set_field_background('age', '#ff0000')             # this set the field 'age' to red color

# Every set functions are batched for speed performance.
# To send the batch update of every set requests you made,
# you need to commit the table object as follow.
table.commit()

Contributing

For guidance on how to make a contribution to Sheetfu, see the contributing guidelines.

Links

If you are looking for the original sheetfu google apps script library, it has been relocated to this page.

sheetfu's People

Contributors

sp-alex-muelas avatar philippe2803 avatar sp-adrian-matteo avatar sp-daniel-sanchez avatar adrianmatteo avatar

Stargazers

 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.