SheetsPersist 1.3.0
See the version list below for details.
dotnet add package SheetsPersist --version 1.3.0
NuGet\Install-Package SheetsPersist -Version 1.3.0
<PackageReference Include="SheetsPersist" Version="1.3.0" />
paket add SheetsPersist --version 1.3.0
#r "nuget: SheetsPersist, 1.3.0"
// Install SheetsPersist as a Cake Addin
#addin nuget:?package=SheetsPersist&version=1.3.0
// Install SheetsPersist as a Cake Tool
#tool nuget:?package=SheetsPersist&version=1.3.0
SheetsPersist
Simple Object Persistence and Logging to Google Sheets
SheetsPersist gives you two ways to integrate .NET object instances with Google Sheets.
- Object Persistence (read and write object instances to/from a spreadsheet).
- Logging (send .NET instances to a rich log kept in a spreadsheet).
Spreadsheet Registration
First, register the spreadsheet you want to work with like this:
GoogleSheets.RegisterDocumentID("LogTest", "1YnqCNZFqfdRP_7ocmAkD0dpI-G_bFnwGH1vN-YppAZE");
The first parameter is the name of the spreadsheet as you would like to refer to it in the code.
The second parameter is the ID of the document. You can get this from the URL.
For example:
docs.google.com/spreadsheets/d/1YnqCNZFqfdRP_7ocmAkD0dpI-G_bFnwGH1vN-YppAZE/edit#gid=835270728
Registration needs to happen when the app first starts up (before you write any data).
Add Attributes to Classes
Any class that needs to be written to or read from a Google Sheet, needs to be adorned with two attributes:
The Document attribute includes the name of the document passed to RegisterDocumentID (see above). This is the spreadsheet that will hold saved instances.
[Document("LogTest")]
The Sheet attribute contains the name of the sheet (tab) to read from or write to.
[Sheet("Today's Results")]
Object Persistence
Specify the properties and fields to read/write using the column attribute, like this:
[Column]
public DateTime Time { get; set; }
In this case, the column header will be "Time". If you want to use a different column name, pass that string in as a parameter to the column attribute, like this:
[Column("Sale Price")]
public decimal Price { get; set; }
You can specify an indexer property (which must have unique values in the spreadsheet), like this:
[Indexer]
[Column]
public Guid ID { get; set; }
If a class has an indexer, when you save it, it will overwrite the data on row where that class data previously existed.
Saving
To save objects adorned with the Document and Sheet attributes (see above), simply call:
GoogleSheets.SaveChanges(...)
Passing the instance or instances you want to save. That's it.
Loading
To load data from a spreadsheet, use:
List<T> results = GoogleSheets.Get<T>()
Where T is the class that has been adorned with the Document and Sheet attributes. That's it.
Object Logging
Object logging is super cool. You can rapidly send many rich log messages to a spreadsheet that you can monitor from anywhere and share easily.
To log an object, call:
GoogleSheets.AppendRow(instance);
Where instance is an instance of the class that has been adorned with the Document and Sheet attributes.
Throttling
Object logging is throttled, so you can send many messages in a short time without exceeding Google API messaging quotas.
The default time between updates is 5 seconds. You can change it like this if you like:
GoogleSheets.TimeBetweenThrottledUpdates = TimeSpan.FromSeconds(10);
We do not recommend dropping this time below 2 seconds because of Google Api Messaging Quotas.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Google.Apis.Sheets.v4 (>= 1.56.0.2371)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.4 | 337 | 2/17/2023 |
1.3.3 | 277 | 1/28/2023 |
1.3.1 | 440 | 3/18/2022 |
1.3.0 | 393 | 3/18/2022 |
1.2.0-alpha | 151 | 2/14/2022 |
1.0.0-alpha | 133 | 2/10/2022 |
0.9.0-alpha | 147 | 2/8/2022 |
Initial