gsheets 0.3.0 copy "gsheets: ^0.3.0" to clipboard
gsheets: ^0.3.0 copied to clipboard

outdated

A library for working with Google Sheets API v4. Manage your spreadsheets with gsheets in Dart.

Gsheets with Dart 📄 #

A library for working with Google Sheets API v4.

Manage your spreadsheets with gsheets in Dart.

Usage 🔧 #

Basic usage see example. For more advanced examples, check out following article Dart: Working With Google Sheets.

If you don't know where to find the credentials, i recommend you to read following article How To Get Credentials for Google Sheets.

  1. After you setup the credentials for your API, you have to download a json from the google console that is like the following:
{
  "type": "service_account",
  "project_id": "",
  "private_key_id": "",
  "private_key": "",
  "client_email": "",
  "client_id": "",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": ""
}

You have to insert that json content in the _credentials variable,so it has to be like this:

const _credentials = r'''
{
  "type": "service_account",
  "project_id": "",
  "private_key_id": "",
  "private_key": "",
  "client_email": "",
  "client_id": "",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": ""
}
''';
  1. Add the spreadsheet id, you can find it in the url of your google sheets document:
https://docs.google.com/spreadsheets/d/spreadsheetId/edit#gid=1590950017

so you have to paste the spreadsheetId in the _spreadsheetId variable:

const _spreadsheetId = 'spreadsheetId';
  1. then you can use the library, here we have some examples, you can check more commands in the example folder
void main() async {
  // init GSheets
  final gsheets = GSheets(_credentials);
  // fetch spreadsheet by its id
  final ss = await gsheets.spreadsheet(_spreadsheetId);
  // get worksheet by its title
  var sheet =  ss.worksheetByTitle('example');
  // create worksheet if it does not exist yet
  sheet ??= await ss.addWorksheet('example');
  // update cell at 'B2' by inserting string 'new'
  await sheet.values.insertValue('new', column: 2, row: 2);
  // prints 'new'
  print(await sheet.values.value(column: 2, row: 2));
  // get cell at 'B2' as Cell object
  final cell = await sheet.cells.cell(column: 2, row: 2);
  // prints 'new'
  print(cell.value);
  // update cell at 'B2' by inserting 'new2'
  await cell.post('new2');
  // prints 'new2'
  print(cell.value);
  // also prints 'new2'
  print(await sheet.values.value(column: 2, row: 2));
 // append row in the followind columns with his values
   final secondRow = {
    'index': '5',
    'letter': 'f',
    'number': '6',
    'label': 'f6',
  };
  await sheet.values.map.appendRow(secondRow);
  // prints {index: 5, letter: f, number: 6, label: f6}
  print(await sheet.values.map.lastRow());
}

Features and bugs 🪲 #

Please file feature requests and bugs at the issue tracker.

241
likes
0
pub points
95%
popularity

Publisher

unverified uploader

A library for working with Google Sheets API v4. Manage your spreadsheets with gsheets in Dart.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, googleapis, googleapis_auth, http, meta

More

Packages that depend on gsheets