Kenton Sparks
Kenton Sparks

Reputation: 145

How can I find the ID of a google sheet that I've just created with code?

I've just created a copy of a file with a new name using this command:

file.makeCopy(''+newfilename+'');  

How can I find the ID of the new file?

Upvotes: 0

Views: 456

Answers (3)

Wicket
Wicket

Reputation: 38416

Use the following

var copy = file.makeCopy('Put the new file name here');
var id = copy.getId();

Related

Upvotes: 0

Marios
Marios

Reputation: 27390

If you check the official documentation, you will see that makeCopy() returns an object of the class File.

The latter has a method getId() which gives you the id of the File.

const newFile = file.makeCopy('newfilename'); // it returns an object of type File
const newFileID = newFile.getId(); // File has a method .getId()

Upvotes: 1

Doom
Doom

Reputation: 236

Just use:

SpreadsheetApp.getActiveSpreadsheet().getId()

Upvotes: 0

Related Questions