GoogleSheetRepository 1.0.1
dotnet add package GoogleSheetRepository --version 1.0.1
NuGet\Install-Package GoogleSheetRepository -Version 1.0.1
<PackageReference Include="GoogleSheetRepository" Version="1.0.1" />
paket add GoogleSheetRepository --version 1.0.1
#r "nuget: GoogleSheetRepository, 1.0.1"
// Install GoogleSheetRepository as a Cake Addin #addin nuget:?package=GoogleSheetRepository&version=1.0.1 // Install GoogleSheetRepository as a Cake Tool #tool nuget:?package=GoogleSheetRepository&version=1.0.1
google-sheet-repository
Badge Statuses
GoogleSheetRepository
Allows execute CRUD operation in google sheet without having to have knowledge on the Google Sheets API methods and protocols.
The following Google Sheets API operations are suported:
- Pagination reading records
- Reading all records
- Appending new records
- Deleting records
- Updating records
The library is written in such a way as to make working with Google spreadsheets as easy as possible. You don't need to know the line number where the object you're interested in is located in order to delete it or update it. The library will do this for you.
Installation
Add nuget package in your project by enter .net CLI
dotnet add package GoogleSheetRepository
You need to setup a Google API Service Account before you can use this library.
- Create a service account. Steps to do that are documented below,
https://cloud.google.com/docs/authentication/production#create_service_account
- After you download the JSON key, you need to decide how you want to store it and load it into the application. In appsettings.json you need write path to file, with name of file like this:
"FCredencialFile": "app_client_secret.json"
in project tree:
- Create google sheet document or use exist. Get from browser sheetId: Enter SheetId to the appsettings.json
"SheetId": "XXX-XXX-XXX-YOUR-CODE-SET-IN-SECRET-XXX-XXX-XXX",
- Use the service account identity that is created and add that email address to grant it permissions to the Google Sheets Spreadsheet you want to interact with.
- Make sure you have completed all settings in:
"GoogleSheetSettings": {
"SheetName": "roles",
"SheetId": "XXX-XXX-XXX-YOUR-CODE-SET-IN-SECRET-XXX-XXX-XXX",
"FCredencialFile": "app_client_secret.json"
}
- Create a class.
public class Product : IEquatable<Product>
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int CategoryId { get; set; }
public bool Equals(Product? other)
{
return Id == other.Id
&& Name == other.Name
&& Price == other.Price
&& CategoryId == other.CategoryId;
}
}
The class must implement the interface IEquatable.
- Create depedency injection:
builder.Services.AddSingleton<IRepository<Product>, Repository<Product>>();
- Start project. In google sheet is created table "Product".
How to read paginated list records
private readonly IRepository<Product> _repository;
var products = _repository.Get(1,1);
How to read all records
private readonly IRepository<Product> _repository;
var products = _repository.Get();
How add record
private readonly IRepository<Product> _repository;
var products = _repository.Add(new Product());
How delete record
private readonly IRepository<Product> _repository;
var items = _repository.Get();
var item = items.FirstOrDefault(x=>x.Id == id);
if (item == null)
{
return NotFound();
}
_repository.Delete(item);
How update record
private readonly IRepository<Product> _repository;
var items = _repository.Get();
var existingItem = items.FirstOrDefault(x => x.Id == id);
if (existingItem == null)
{
return NotFound();
}
_repository.Update(existingItem, updatedItem);
Sample project
In repository sample project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Google.Apis.Sheets.v4 (>= 1.62.0.3148)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
base version