How to read data from Google spreadsheet in xamarin.forms

后端 未结 3 1246
醉酒成梦
醉酒成梦 2020-12-10 10:26

I am searching for a way to read/write data from Google Sheets directly. Does anyone have an idea how to do that in Xamarin.Forms?

Kee

相关标签:
3条回答
  • 2020-12-10 10:44

    Reading & writing data on spread sheet is not an easy thing. I would suggest you go with WebView that might solve you issues. Here you might found some clue to do so

    https://www.twilio.com/blog/2017/03/google-spreadsheets-and-net-core.html

    & here on Google.Apis.Sheets.v4 API's are

    https://github.com/xamarin/google-apis

    & Spreadsheets with C#

    Accessing Google Spreadsheets with C# using Google Data API

    0 讨论(0)
  • 2020-12-10 10:53

    I created the following Solution and it is working fine for me:

    You Need to use JSON result from Google sheet, try to use the following steps:

    1-Publish a google sheet to get an API link that returns JSON, like the following Sheet:

    https://spreadsheets.google.com/feeds/list/1opP1t_E9xfuLXBkhuyzo5j9k_xBNDx0XKb31JwLP1MM/1/public/values?alt=json

    2-You need to generate C# Classes from JSON, maybe you are able to use http://json2csharp.com To get the C# Classes and the RootObject.

    3- Add The following Code:

       HttpClient client = new HttpClient();
       string URL = "https://spreadsheets.google.com/feeds/list/1opP1t_E9xfuLXBkhuyzo5j9k_xBNDx0XKb31JwLP1MM/1/public/values?alt=json";
       var response = await client.GetAsync(string.Format(url));
       string result = await response.Content.ReadAsStringAsync();
       RootObject root = JsonConvert.DeserializeObject<RootObject>(result);
    

    From the root object, you will be able to access any cell value on the Google sheet.

    0 讨论(0)
  • 2020-12-10 11:02

    Despite the fact that it really isn't a good idea to use Google Sheets as your online database, there are many better alternatives, if you want to access it from a Xamarin Forms app you can do it using the Sheets API

    Sheets API documentation here

    0 讨论(0)
提交回复
热议问题