Google Sheet api v4 dynamic sheet range - c#

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

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

C# - Google Sheets API, how to retrieve an image place in cell?

I have a .net core 3.1 console app that I need to use to connect to my Google Sheet and export data to a PDF file.
I can retrieve all the textual data using service.Spreadsheets.Values.Get(spreadsheetId, $"{spreadsheetName}!C2:C8");
The issue I'm facing is that in cells B2:B8 (those are merged cells) I have an image which I've uploaded from my local folder (Image -> Insert -> Image in cell -> Upload) and I can't seem to retrieve that image.
When I call service.Spreadsheets.Values.Get(spreadsheetId, $"{spreadsheetName}!B2:B8"); the Values property returns null
I've tried using =image("IMAGE_URL") in the cell instead of uploading the image but that didn't work as well.
Also, the preferred option would be to use the first approach of uploading the image into the cell so I won't have to find where to store my images.
Is this even possible to accomplish?
That's a very popular feature request
However, as of now it has not been implemented yet - given that images in cells are a rather new feature.
There are however some workarounds - either using Apps Script or a vlookup formula, have a look here.

Read the xls file from Sharepoint using MS graph api for unknown range

I need to access the xls file from sharepoint using Microsoft graph API and parse it.
This url gives correct data when the worksheet name and range is known.
/sites/site-Id/drives/drive-id/items/item-id/workbook/worksheets('Sheet1')/range(address='A1:C3')
But I am not sure how to get the data when the range is not known.
Thanks,
Unfortunately there is no way to read all data cells without giving the range as of now, you can however voice your interest in such a feature by going on to the Microsoft Graph Feedback Forum.

How to read data from Google spreadsheet in 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?
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

Categories