DEV Community

Cover image for Google Sheets with .Net Core Razor Pages CRUD Tutorial
Zoltan Halasz
Zoltan Halasz

Posted on

Google Sheets with .Net Core Razor Pages CRUD Tutorial

In my research related to Asp.Net core, I came across a simple example using Google Sheets (spreadsheet) integrated into a .net core app. Actually, in the past days I met a programmer friend who explained another app of his, that uses a google spreadsheet for back-end. That's why I decided to give it a try, check the below tutorial and adapt it to a full CRUD.

https://dottutorials.net/google-sheets-read-write-operations-dotnet-core-tutorial/

Please note that the above is a console app, and mine is a Razor pages CRUD, with added functionality, using the basic points from the above, but also extending the logic of it.

The initial settings are very well explained in the above tutorial, so you can check and follow how to create a google API and credentials etc, add nuget package for your app, which are the starting point for my app.

For our example, create a second sheet called Sheet2, which will contain a list of invoices, as presented in my sheet (see link, only read-only access granted).

My CRUD application is running under:

https://googlesheets.azurewebsites.net/InvoiceList

a. The base class for the invoice list looks as below:

public class InvoiceModel
    {

        public int Id { get; set; }

        public int InvoiceNumber { get; set; }

        public string CostCategory { get; set; }

        public string Period { get; set; }

        public double Amount { get; set; }

    }
Enter fullscreen mode Exit fullscreen mode

b. The additional work in my case is a service class that supplies the CRUD operations, just as seen below.

This service uses the google api for spreadsheets. My resource was the above mentioned tutorial, with some modifications, using stack overflow etc.

I will attach only the service class.
https://drive.google.com/open?id=1mjxgBa5n6C3zcZTsnNx8jgF8OOkbqgoq

Let me know if any of you need the full code of the app.

Discussion (2)

Collapse
solazo profile image
solazo

Can i have the full code sir?

Collapse
zoltanhalasz profile image
Zoltan Halasz Author

I am sorry, I must have deleted it. Just have a look if you can build something from the main class

I will attach only the service class.
drive.google.com/open?id=1mjxgBa5n...