Please tell me how in the Google Sheets API you can not manually get the range of the entire table located on a certain sheet.
I have a table in which the number of columns can change, but I still have to get information from it.
sheet = service.spreadsheets().values().get(
spreadsheetId=spreadsheet_id, range='???').execute()
You can you sheet.getDataRange() to get range of the visible data on your spreadsheet.
solution:
sheet = service.spreadsheets().values().get(
spreadsheetId=spreadsheet_id,
range='Sheet1',
majorDimension='ROWS').execute()
Is there any way to find the last row you have written in a google spreadsheet in Java?
I tried to do that by having a variable which I keep in another file and I update that every time I do another writing. Is there any other way?
Finding last written row in Google Spreadsheet API
I'll give you a concept first using REST calls but you'll have to apply that in Java.
Exceed the range of cells where you're writing.
So to find last written row between cells A1:A10, use the range A1:A11 or A1:B (using B means all the rows in cell A will be traversed).
Fetch a range of cells, using GET. Parse the response result. And get the length of the parsed values. The length will always indicate the last row since Sheetsv4 ignores blank/empty cells.
So example I have a range of cells between A1:A10. I wrote "hello" in A10. Following the concepts above I do this:
..
xhr.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/'+myspreadsheetId+'/values/Sheet1!A1:A10);
..
xhr.onload = function (oEvent) {
arrayBuffer = xhr.response;
myArray = JSON.parse(arrayBuffer);
console.log("last row is " + myArray.values.length)
.. //output is 'last row is 10'
This part of my XHR request returns 10. Now I know that the last written row in my sheet is A10.
To do this in Java use the solution based on this SO thread.
mService.spreadsheets().values().get("ID_SHEET", "Sheet1!A1:B").execute();
Also check this thread about writing on data cells using Java. I think it offers additional insight as well.
I am moving over a worksheet from GoogleDocs that has to be in Excel now.
It is a barcode generator sheet.
The image cell in GoogleDocs has the formula is
=image("www.somebarcodesite.com/image.php?code=" & A2 & "&style=197&type=C128B&width=300&height=50&xres=1&font=3", 3)
I've downloaded as Excel but that has not helped (I think due to text concatenation) and additional rows may be need to be added so it's not enough to embed the image once when downloading.
I've seen VB solutions to put an image in a cell, but I'm not sure it would allow the users to add new rows to the worksheet.
Does anyone know where I should start on finding a scalable way to show the image generated at a url, where the url is generated dynamically based on the input of other cells?
How to get feeds from multiple sheets using google spreadsheet feeds api?
Below URL fetches the feeds from first sheet only. In my spreadsheet I have 3 work sheets and I want to fetch remaining sheets data as well.
https://spreadsheets.google.com/feeds/list/XXXXMYKEYXXXX/od6/public/values?alt=json-in-script
How to fetch them?
I tried below without success:
https://spreadsheets.google.com/feeds/list/XXXXMYKEYXXXX/od7/public/values?alt=json-in-script
Note od7 instead of od6
UPDATE
URL for the spreadsheet feed is
https://spreadsheets.google.com/feeds/list/1c53H0piyduOV6zRwS54A7MDZ3SooJOmj4O52Xd0dyIA/od6/public/values?alt=json-in-script
In the spreadsheet I have TopicA,TopicB,TopicC sheets. Feeds response contains TopicA information only.
It seems worksheet IDs are numbered from 1 to n and not like od6, od7.
Using below urls, I was able to get individual worksheet's data
https://spreadsheets.google.com/feeds/list/1c53H0piyduOV6zRwS54A7MDZ3SooJOmj4O52Xd0dyIA/1/public/values?alt=json fetches first worksheet
https://spreadsheets.google.com/feeds/list/1c53H0piyduOV6zRwS54A7MDZ3SooJOmj4O52Xd0dyIA/2/public/values?alt=json 2nd sheet
https://spreadsheets.google.com/feeds/list/1c53H0piyduOV6zRwS54A7MDZ3SooJOmj4O52Xd0dyIA/3/public/values?alt=json 3rd sheet and so on
Note the /1, /2 and /3 after the key (1c53H0piyduOV6zRwS54A7MDZ3SooJOmj4O52Xd0dyIA) in the url
Per the Google Spreadsheets API:
To determine the URL of a given spreadsheet's worksheets feed, find
that spreadsheet's entry in the spreadsheets feed, as described in the
previous section. Then examine the link element that has
rel="http://schemas.google.com/spreadsheets/2006#tablesfeed". That
element's href value provides the URL for that spreadsheet's
worksheets feed.
To request a list of worksheets in a given spreadsheet, issue a GET
request to that URL, with an appropriate authorization header:
GET https://spreadsheets.google.com/feeds/worksheets/key/private/full
The returned result contains a URL for each worksheet in that spreadsheet, which you can then query to pull information from each worksheet you want to get data from. So in your example, od6 is a valid worksheetId, but you must discern the other worksheetIds from the spreadsheet's feed.
Building on suman j's answer, here's a way to load multiple sheets, regardless of how many there are, using jQuery.
Load the spreadsheet's main JSON feed, find the url for each sheet in the JSON that's returned, tweak the url a bit, then load that one as well. Then use ajaxStop to take any action that needs to happen after they all finish loading.
$(function(){
var feedurl_start = "https://spreadsheets.google.com/feeds/";
var feedkey = "1c53H0piyduOV6zRwS54A7MDZ3SooJOmj4O52Xd0dyIA";
$.getJSON(feedurl_start+"worksheets/"+feedkey+"/public/basic?alt=json", function(sheetfeed) {
$.each(sheetfeed.feed.entry, function(k_sheet, v_sheet){
var sheeturl = v_sheet.link[0]["href"]+"?alt=json";
sheeturl = sheeturl.replace("basic", "values");
var sheet_title = v_sheet.content["$t"]; // to know which sheet you're dealing with
console.log(sheet_title);
$.getJSON(sheeturl, function(sheetjson){
console.log(sheetjson);
});
});
});
});
// Since you're making multiple AJAX calls, use ajaxStop
// to do whatever you need to do AFTER everything is loaded
$( document ).ajaxStop(function() {
// now all your data is loaded, so you can use it here.
});
I'm working on a feedback system for my math students and have a matrix that shows what points they have gotten on a test.
I have several sheets in this document with one sheet per student. I have also made one spreadsheet per student that i have put in a shared folder on Google Drive where the students only have viewing rights.
What I want to do is copy the entire sheet from my master document to the student's spreadsheet. This is all fine if I use the import range function however with that the formatting doesn't follow.
Is it possible to use a script with the commands getBackgroundColor() and setBackgroundColor() to transfer the backgroundcolors from the master sheet to the students sheet?
I started with something like this:
function getColor() {
var sheet = SpreadsheetApp.openById("0ApOkn5XcO_GDdFd4SDBaaFpLSEUxXy1vN2pnNHBpYnc");
var ss=sheet.getSheetByName("Student1");
var r=ss.getRange("A1:R34");
var color = ss.getBackgroundColors();
That's about as far as I get. Anyone have ideas?