Get owner information
This article explains the method to use when you want to get the owner of a specific spreadsheet.
Method to use
Section titled “Method to use”Spreadsheet.getOwner();Use getOwner(), which is provided by the Spreadsheet class.
Because the script accesses the spreadsheet, you may need to authorize it the first time you run it.
Sample code
Section titled “Sample code”/** * ID of the target spreadsheet * The xxx part of https://docs.google.com/spreadsheets/d/xxx/edit */const SPREAD_SHEET_ID = '_______________';
/** * Returns the owner information of the spreadsheet */const getSpreadSheetOwner = () => { /** Target spreadsheet */ const ss = SpreadsheetApp.openById(SPREAD_SHEET_ID);
/** Owner of the spreadsheet */ const owner = ss.getOwner();
// Files in a shared drive have no owner, so null is returned if (!owner) { console.log('There is no owner (the file is in a shared drive)'); return null; }
console.log(owner.getEmail());
return owner;};When you run it, the email address of the target spreadsheet’s owner appears in the log.
The owner information is returned as a User class object.
However, spreadsheets stored in a shared drive have no owner, so null is returned.
Currently, the only value you can get from the User class is the email address (getEmail()).
If security policies don’t allow access to the email address, an empty string is returned.