Skip to content

Get data from spreadsheet

Danylo Lytvynenko edited this page Sep 23, 2020 · 7 revisions

Warning: If the cells in the google table are not filled with data, as in the example below, then when accessing the cell by address it will not match the address in the google table, since transferring information, the site api ignores empty cells (but the lines remain unchanged, even if all its cells are empty)

image


Get spreadsheet

First you need to get the desired saved spreadsheet

var spreadsheet = GoogleDocConnector.GetSpreadsheet("{ID}");

Also, if you need from this class, you can get the absolute web url for the spreadsheet. string url = GoogleDocConnector.GetSpreadsheetWebUrl("{ID}");

Get sheet

There are 2 ways to get the sheet you need, here they are:

  1. Use methods
+ Gets spreadsheet sheet by it's id.
var sheet = spreadsheet.GetSheet(500028786);
+ Gets first spreadsheet sheet by it's name.
sheet = spreadsheet.GetSheet("Sheet1");

Also you can check if this sheet is there

+ Returns `true` if spreadsheet contains a sheet with specified id, otherwise `false`.
bool checkSheetId = spreadsheet.GetSheet(500028786);
+ Returns `true` if spreadsheet contains a sheet with the name, otherwise `false`.
bool checkSheetName = spreadsheet.GetSheet("Sheet1");
  1. The second way is to get a list of sheets var sheets = spreadsheet.Sheets and work with it yourself var sh = sheets.First(); or smth else

Get cell

When you find the sheet you want, then you can get any cell that is filled and store there

  1. Use methods
+ Get sell by name.
var cell = spreadsheet.GetCell("B5");
+ Gets cell from specified row & col. Indexs starts from 0
var cell1 = spreadsheet.GetSheet(0, 2); // C1
  1. The second way is to get a list of Rows var rows= sheet.Sheets and work with it yourself var sh = sheets.First(); or smth else
Clone this wiki locally