PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 13, 2022

[FIXED] How to read data from Google spreadsheet in xamarin.forms

 September 13, 2022     c#, cross-platform, google-api, google-sheets, xamarin.forms     No comments   

Issue

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?

Keep in your mind access Google sheets from Windows Form working fine with me using Install-Package Google.Apis.Sheets.v4 Package.

I Used the following link:

https://developers.google.com/sheets/api/quickstart/dotnet


Solution

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.



Answered By - Mohamad Mahmoud Darwish
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing