GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — GoogleAPI-Library/GoogleAPI-Library/GoogleSheetsManager.cs at main · G0gix/GoogleAPI-Library Expand file tree/ Copy pathGoogleSheetsManager.csMore file actions 76 lines (69 loc) · 2.73 KB / Copy pathGoogleSheetsManager.csFile metadata and controls76 lines (69 loc) · 2.73 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 using Google.Apis.Sheets.v4; using Google.Apis.Sheets.v4.Data; using GoogleAPI_Library.Exceptions.GoogleSheets; using GoogleAPI_Library.Models.GoogleSheet; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace GoogleAPI_Library { /// <summary> /// Allows you to perform basic operations with Google Spreadsheet. /// The call to the InitializeAsync method is required /// </summary> public class GoogleSheetsManager { private SheetsService Service; public GoogleSheetsManager(SheetsService service) { Service = service; } /// <summary> /// Allows to insert data from the table according to the specified settings. /// API key is not supported as a credential for this method /// </summary> /// <param name="writeOptions">Data insertion settings</param> /// <param name="dataToInsert">Data to insert</param> /// <returns></returns> /// <exception cref="GoogleSheetsException">Represents errors that occur during request to Google sheets.</exception> public async Task WriteAsync(GoogleSheetOptions writeOptions, IList<IList<object>> dataToInsert) { try { if (dataToInsert.Count == 0 || dataToInsert == null) { return; } ValueRange valueRange = new ValueRange(); valueRange.Values = dataToInsert; var appendRequest = Service.Spreadsheets.Values.Append(valueRange, writeOptions.SheetId, writeOptions.SheetRange); appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED; await appendRequest.ExecuteAsync(); } catch (Exception ex) { throw new GoogleSheetsException(ex.Message); } } /// <summary> /// Allows to get data from the table according to the specified settings. /// </summary> /// <param name="readOptions"></param> /// <returns></returns> /// <exception cref="GoogleSheetsException"></exception> public async Task<IList<IList<Object>>> ReadAsync(GoogleSheetOptions readOptions) { try { var request = Service.Spreadsheets.Values.Get(readOptions.SheetId, readOptions.SheetRange); ValueRange response = await request.ExecuteAsync(); IList<IList<Object>> values = response.Values; return values; } catch (Exception e) { throw new GoogleSheetsException(e.Message); } } } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |