read data from another spreadSheet

1,150 views
Skip to first unread message

François Baury

unread,
Oct 9, 2022, 11:15:55 AM10/9/22
to Google Apps Script Community
Hi,

I work on a program in a spreadsheet.
I need to read data in another spreadsheet.

I don't know how to do this.

Thanks

CBMServices Web

unread,
Oct 9, 2022, 1:29:30 PM10/9/22
to google-apps-sc...@googlegroups.com
Hi Francois,

Reading data from another sheet is the same as reading data from the sheet open. You just need to reference the sheet by opening the spreadsheet first using it ID or its URL.

Use:

var ss = SpreadsheetApp.openById(" put id here.. ");
var sheet = ss.getSheetByName(" put sheet name here ");

Then you can specify range and get or set values in that range.

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/f27796c9-6320-4180-879b-f08381b341f3n%40googlegroups.com.

François Baury

unread,
Oct 9, 2022, 2:58:52 PM10/9/22
to Google Apps Script Community
Thank you George.

My program work now.

Cemal Karabulaklı

unread,
Oct 11, 2022, 8:19:46 AM10/11/22
to Google Apps Script Community
Hi, 
The logic is the same as reading on the same spreadsheet. Only you will get the other sheets by Id. Here is the example

var sheetActive = SpreadsheetApp.openById("ID"); 
var sheet = sheetActive.getSheetByName("Name");

Suresh Kumar

unread,
Oct 12, 2022, 1:51:13 AM10/12/22
to Google Apps Script Community
Hi, Is it possible to copy a row to another spreadsheet? Not between tabs.
And 
I want to achieve this using a standalone script. (Just coz I don't want my editors to view my code)

CBMServices Web

unread,
Oct 12, 2022, 1:53:33 PM10/12/22
to google-apps-sc...@googlegroups.com
You should be able to do that. However, I believe(not sure), that copy To method only works within the same spreadsheet. So you can not use that method I think.  So what you will need to do is read the row, then write it to the new spreadsheet.

Print this mail only if absolutely necessary. Save Paper. Save Trees.

The information contained in this email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. It may contain legally privileged, proprietary and confidential information. If you are not the intended recipient, you are hereby notified that all the contents of this email including the attachments must not be reprinted, read, copied, disclosed, forwarded, disseminated, distributed or used (in any manner whatsoever) by any person other than the addressee is strictly prohibited and may constitute unlawful act and can possibly attract legal action, civil and/or criminal. You are further requested to kindly notify us immediately by responding to this email and then delete it permanently from your system.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Message has been deleted

Peter Lawlor

unread,
Nov 2, 2022, 4:58:13 AM11/2/22
to Google Apps Script Community
Hi Suresh,

I think this may be of use to you, I use a script to convert xlsx to gsheet and then copy the converted data to another existing gsheet, here's the snippet that copies the data: 

var xlsxBlob = attachments[0]; // Is supposes that attachments[0] is the blob of xlsx file.
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id;
var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // There is the data in 1st tab.
var data = sheet.getDataRange().getValues();
Drive.Files.remove(convertedSpreadsheetId); // Remove the converted file.

var sheet = SpreadsheetApp.openById("Link to sheet").getSheetByName("Page");
sheet.clearContents();
var range = sheet.getRange(1, 1, data.length, data[0].length);
range.setValues(data);
}
Reply all
Reply to author
Forward
0 new messages