如何在xamarin.forms中从Google电子表格中读取数据 [英] How to read data from Google spreadsheet in xamarin.forms
问题描述
我正在寻找直接从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 sheets
的访问对我来说很好.
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工作表以获取一个返回 JSON 的 API 链接,例如以下工作表:
1-Publish a google sheet to get an API link that returns JSON, like the following Sheet:
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屋!