如何在 xamarin.forms 中从 Google 电子表格中读取数据 [英] How to read data from Google spreadsheet in xamarin.forms

查看:22
本文介绍了如何在 xamarin.forms 中从 Google 电子表格中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种直接从 Google Sheets 读取/写入数据的方法.有没有人知道如何在 Xamarin.Forms 中做到这一点?

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?

请记住,使用 Install-Package Google.Apis.Sheets.v4 包从 Windows 表单访问 Google 表格 对我来说工作正常.

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

我使用了以下链接:

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

推荐答案

我创建了以下解决方案并且对我来说效果很好:

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

您需要使用来自 Google 表格的 JSON 结果,请尝试使用以下步骤:

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

1-发布一个 google 表格以获取返回 JSONAPI 链接,如下面的表格:

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-您需要从 JSON 生成 C# 类,也许您可​​以使用http://json2csharp.com 获取 C# 类和 RootObject.

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- 添加以下代码:

   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);

root 对象,您将能够访问 Google 工作表上的任何单元格值.

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

这篇关于如何在 xamarin.forms 中从 Google 电子表格中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆