How to read data from Google spreadsheet in xamarin.forms - c#

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

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

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.

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

Related

Create online sheets using C#, SQLServer and AngularJS

I want to achieve the following -
1)Connect to SQL Server Database to get JSON data.
2)Use the JSON data to create spreadsheet like tables with multiple tabs.
3)The spreadsheet can be edited to have additional calculated features like math functions etc.
4)Create another tab depending on data present in the spreadsheet tabs
5)Publish this spreadsheet as a view only spreadsheet.
Is this possible? I am open to use any JS library.
I am looking for any excel like application which gives us the opportunity to create the spreadsheet with multiple tab + formulas and share/socialize it.
What is the best way/example to go about implementing this feature? I want it to work with AngularJS, JavaScript.
Like mentioned previously, the best solution for this would be to start with the Sheets API Quickstart for .NET here.
After you start getting a grasp on how the Sheets API works, you can easily connect to the SQL Server and retrieve the data you want in order to create a spreadsheet with your requirements.
You might find the following links useful:
spreadsheets.create - request to create a spreadsheet which will return the newly created spreadsheet
spreadsheets.values.batchUpdate - request to write multiple values in a spreadsheet
spreadsheets.values.append - request to append values to a spreadsheet
Reference
Sheets API Quickstart;
Google Sheets API Client Library for .NET.

Different mechanisms to create google sheets

Are there any options apart from using the Google API for creating Google sheets?
For example, with Excel, I can create them using interop, or EPPlus or by creating a spreadsheet XML format.
Answer:
The only ways to create a Google Sheet are:
Programmatically using the Sheets API using the Spreadsheets.create() method.
Clicking one of the templates under Start a new Spreadsheet at sheets.google.com.
Directly visiting the /create endpoint at docs.google.com/spreadsheets/create Either in the browser or by making a programmatic HTTP request with a library such as HttpWebRequest/WebClient/HttpClient
Following in the File > New > Spreadsheet menu item from an already-open Spreadsheet File in the Browser.
Following the + New > Google Sheets menu item at drive.google.com and using either the Blank Spreadsheet or From a template options.
Using some third-party library such as GSpread.NET to read/write Google Sheets as normal Excel documents (not supported by Google, though these also just use the API as in the first bullet point).

Google Sheet api v4 dynamic sheet range

I am trying to access a sheet to get data and copy it in a data table I'm using the google sheets api v4 but I found that I must add the range to the request params.
Although I can't know how many columns has data in that sheet but the user is the one who set the spreadsheet url, so it varies and I can't find the specific range to add to the request.
So how can I find the range with contains all the data of that spreadsheet (knowing that all the spreadsheets the use can choose has only one sheet).
Answer:
Unfortunately, there is no way of retrieving the data range of a sheet using the Google Sheets API.
Workarounds:
Google Apps Script has a .getDataRange() method of the Sheet class, which returns in A1 notation the range in which data is present in a Sheet. There is a workaround here which incorporates this method, though I am unsure if it is suitable for your use case.
Feature Request:
You can however let Google know that this is a feature that is important for the Sheets API and that you would like to request they implement it. Google's Issue Tracker is a place for developers to report issues and make feature requests for their development services. The page to file a Feature Request for the Google Sheets API is here.
References:
How to get data range of a sheet (Google Sheets API)
Google's Issue Tracker
Feature Request form for Google Sheets API

Creating docx OOXML with c#

I was hoping for a good point in the correct direction, as this is something I have never done, and googling is getting me tied in knots.
I want to create a word document (docx) from C# on a ASP.NET MVC application.
Populating a template with something like mail merge would be great.
I have spent day googling this and keep finding archived documentation.
The following examples are from 2012
https://msdn.microsoft.com/en-us/library/office/bb491088.aspx
Because you will generate documents on the server you should avoid Interop for document manipulation. You can use free libraries and SDKs based on OpenXML but this is difficult to learn and error prone.
It probably makes sense to choose one among 3rd party toolkits to get the job done quick and easy. Start by preparing MS Word template documents with placeholders for data. Then you can use c# to load the data for the reports and merge the data with templates to get final documents (docx, pdf, xps or image formats). Here is the code used by one such toolkit needed for merging data from the database with the template to get a pdf document:
IEnumerable<Customer> customers = DataAccess.GetCustomerById(15);
DocumentGenerator dg = new DocumentGenerator(customers);
DocumentGenerationResult result = dg.GenerateDocument("MyTemplate.docx", "MyReport.pdf");
You can also see these examples for more information.
Maybe Templater can be of help..
This is small library you can use to create word document on ASP.NET looking like mail merge...
Try demo http://templater.info/demo

what is baseURI field in gData?

I was trying to integrate Google Docs to a Windows app. In the DocReq class there is a property called baseURI. I have no clue what it is. Also, let me know if there are any examples for the Google Spreadsheets in C#
The baseURI is simply the base URI for the Document request. This wikipedia article explains a URI
http://en.wikipedia.org/wiki/Uniform_Resource_Identifier
Here is another question from Stackoverflow that has some examples about google spread sheets in c#
Accessing Google Spreadsheets with C# using Google Data API

Categories