How to get sheet that is not first sheet?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am new to Google scripting, so I apologize if this is a naive question. I do not know how to get a variable reference to a sheet within a spreadsheet that is not the first sheet.
In my spreadsheet, I have two sheets, Agenda
and Info
. Agenda is the first sheet(index 0) and Info is the second. I can get a reference to Agenda
, but I cannot get a reference to Index. This is the code I have tried:
var info_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Info');
info_sheet.getName()
always comes out being Agenda
, though. What do I do?
google-apps-script google-sheets
add a comment |
I am new to Google scripting, so I apologize if this is a naive question. I do not know how to get a variable reference to a sheet within a spreadsheet that is not the first sheet.
In my spreadsheet, I have two sheets, Agenda
and Info
. Agenda is the first sheet(index 0) and Info is the second. I can get a reference to Agenda
, but I cannot get a reference to Index. This is the code I have tried:
var info_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Info');
info_sheet.getName()
always comes out being Agenda
, though. What do I do?
google-apps-script google-sheets
add a comment |
I am new to Google scripting, so I apologize if this is a naive question. I do not know how to get a variable reference to a sheet within a spreadsheet that is not the first sheet.
In my spreadsheet, I have two sheets, Agenda
and Info
. Agenda is the first sheet(index 0) and Info is the second. I can get a reference to Agenda
, but I cannot get a reference to Index. This is the code I have tried:
var info_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Info');
info_sheet.getName()
always comes out being Agenda
, though. What do I do?
google-apps-script google-sheets
I am new to Google scripting, so I apologize if this is a naive question. I do not know how to get a variable reference to a sheet within a spreadsheet that is not the first sheet.
In my spreadsheet, I have two sheets, Agenda
and Info
. Agenda is the first sheet(index 0) and Info is the second. I can get a reference to Agenda
, but I cannot get a reference to Index. This is the code I have tried:
var info_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Info');
info_sheet.getName()
always comes out being Agenda
, though. What do I do?
google-apps-script google-sheets
google-apps-script google-sheets
edited Jan 4 at 2:34
Rubén
11.4k53670
11.4k53670
asked Dec 11 '13 at 7:26
CaseyCasey
1,04421627
1,04421627
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
There are 2 ways to get access to a specific sheet in a spreadsheet : by its name as you were showing in your code or by its index like in the second example below.
Just run this test to see the results on a spreadsheet with at least 2 sheets (I changed the sheet names to the 'standard default values in US locale' to make the test working for anyone, re-set it to your parameters if needed)
function testSheetNames(){
var info_sheet_example1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var info_sheet_example2 = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
Logger.log('name method result = '+info_sheet_example1.getName());
Logger.log('index method result = '+info_sheet_example2.getName());
}
That said, your example should return the correct value, I'm not sure why it didn't in your tests.
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20513002%2fhow-to-get-sheet-that-is-not-first-sheet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are 2 ways to get access to a specific sheet in a spreadsheet : by its name as you were showing in your code or by its index like in the second example below.
Just run this test to see the results on a spreadsheet with at least 2 sheets (I changed the sheet names to the 'standard default values in US locale' to make the test working for anyone, re-set it to your parameters if needed)
function testSheetNames(){
var info_sheet_example1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var info_sheet_example2 = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
Logger.log('name method result = '+info_sheet_example1.getName());
Logger.log('index method result = '+info_sheet_example2.getName());
}
That said, your example should return the correct value, I'm not sure why it didn't in your tests.
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
add a comment |
There are 2 ways to get access to a specific sheet in a spreadsheet : by its name as you were showing in your code or by its index like in the second example below.
Just run this test to see the results on a spreadsheet with at least 2 sheets (I changed the sheet names to the 'standard default values in US locale' to make the test working for anyone, re-set it to your parameters if needed)
function testSheetNames(){
var info_sheet_example1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var info_sheet_example2 = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
Logger.log('name method result = '+info_sheet_example1.getName());
Logger.log('index method result = '+info_sheet_example2.getName());
}
That said, your example should return the correct value, I'm not sure why it didn't in your tests.
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
add a comment |
There are 2 ways to get access to a specific sheet in a spreadsheet : by its name as you were showing in your code or by its index like in the second example below.
Just run this test to see the results on a spreadsheet with at least 2 sheets (I changed the sheet names to the 'standard default values in US locale' to make the test working for anyone, re-set it to your parameters if needed)
function testSheetNames(){
var info_sheet_example1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var info_sheet_example2 = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
Logger.log('name method result = '+info_sheet_example1.getName());
Logger.log('index method result = '+info_sheet_example2.getName());
}
That said, your example should return the correct value, I'm not sure why it didn't in your tests.
There are 2 ways to get access to a specific sheet in a spreadsheet : by its name as you were showing in your code or by its index like in the second example below.
Just run this test to see the results on a spreadsheet with at least 2 sheets (I changed the sheet names to the 'standard default values in US locale' to make the test working for anyone, re-set it to your parameters if needed)
function testSheetNames(){
var info_sheet_example1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var info_sheet_example2 = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
Logger.log('name method result = '+info_sheet_example1.getName());
Logger.log('index method result = '+info_sheet_example2.getName());
}
That said, your example should return the correct value, I'm not sure why it didn't in your tests.
edited Dec 11 '13 at 12:16
answered Dec 11 '13 at 8:35
Serge insasSerge insas
36.1k45891
36.1k45891
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
add a comment |
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
You're right! Your example worked and so did mine. It turned out that I misspelled my variable by one letter. I'm sure we've all done that before...
– Casey
Dec 11 '13 at 17:34
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
And thank you for being patient with me and not putting a sarcastic answer about how I should have known. I really liked your answer and gave you an upvote for it as well.
– Casey
Dec 11 '13 at 17:40
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
Thanks, you're welcome... For sure I've done that kind of error too... so obvious that we just don't see it :-)
– Serge insas
Dec 11 '13 at 17:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20513002%2fhow-to-get-sheet-that-is-not-first-sheet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown