Selecting a specific sheet based off either number from 0 or nameExport (or print) with a google script new version of google spreadsheets to pdf file, using pdf optionsHow to convert a Google Docs-File to an Excel-File (XLSX)Request Failed for URL Returned Code 404Google Apps Script UrlFetchApp returns 404 when the URL existsUrlFetch getting 404 error from spreadsheet URLGoogle sheet Duplicatea specific sheet from a specific sheet and specific cellGoogle Script - Multi cells copy from a sheet to another with “if empty” checkExport Google Sheet to PDF Programmatically with Custom ParametersPrint a certain range of a Google Spreadsheet using a scriptName a sheet based on a cell in that sheet

For a MOSFET, does capacitive gate current only flow through to the source?

Sitecore Powershell extensions module compatibility with Sitecore 9.2

Is Grandpa Irrational? Another Grandpa Mystery

Why are angular mometum and angular velocity not necessarily parallel, but linear momentum and linear velocity are always parallel?

'static' value appears to reset after function call

Symbol of the tennis ball

How do I run a game when my PCs have different approaches to combat?

How can I stop myself from micromanaging other PCs' actions?

Where is this photo of a group of hikers taken? Is it really in the Ural?

If my business card says 〇〇さん, does that mean I'm referring to myself with an honourific?

What is the purpose of the fuel shutoff valve?

Using "Kollege" as "university friend"?

Area of parallelogram = Area of square. Shear transform

What is a reasonable time for modern human society to adapt to dungeons?

What do I do when a student working in my lab "ghosts" me?

Film where a boy turns into a princess

Historicity doubted by Romans

Inadvertently nuked my disk permission structure - why?

Book with a female main character living in a convent who has to fight gods

Why is chess failing to attract big name sponsors?

Direct revelation mechanism's sets of strategies and types

Spoken encryption

Impact of throwing away fruit waste on a peak > 3200 m above a glacier

Determine if a triangle is equilateral, isosceles, or scalene



Selecting a specific sheet based off either number from 0 or name


Export (or print) with a google script new version of google spreadsheets to pdf file, using pdf optionsHow to convert a Google Docs-File to an Excel-File (XLSX)Request Failed for URL Returned Code 404Google Apps Script UrlFetchApp returns 404 when the URL existsUrlFetch getting 404 error from spreadsheet URLGoogle sheet Duplicatea specific sheet from a specific sheet and specific cellGoogle Script - Multi cells copy from a sheet to another with “if empty” checkExport Google Sheet to PDF Programmatically with Custom ParametersPrint a certain range of a Google Spreadsheet using a scriptName a sheet based on a cell in that sheet






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to generate an email with a PDF attachment of a specific sheet, not necessarily the active sheet. I have tried referencing the specific sheet name as well as the number, but to no avail, it chooses sheet 1, titled 'AMDashboard_English'. Please help.



function CreatePDF() 
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AMDashboard_English");
var sheet = ss.getSheetByName("AMDashboard_English");
Logger.log(sheet.getName());

var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", sheet.getId());

var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls /

var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();

var blobs = [];
var i=0

var response = UrlFetchApp.fetch(
url + url_ext + sheets[i].getSheetId(),
headers: 'Authorization': 'Bearer ' + token

);

blobs[i] = response.getBlob().setName(sheets[i].getName() + '.pdf');
DriveApp.createFile(blobs[i]);
return blobs[i];










share|improve this question



















  • 1





    a workbook ID (SpreadsheetApp.getActive().getId()) and a sheet ID (aka grid ID, SpreadsheetApp.getActive().getSheetByName("some name").getSheetId()) are not the same thing. developers.google.com/sheets/api/guides/concepts#common_terms

    – tehhowch
    Mar 26 at 20:44

















0















I am trying to generate an email with a PDF attachment of a specific sheet, not necessarily the active sheet. I have tried referencing the specific sheet name as well as the number, but to no avail, it chooses sheet 1, titled 'AMDashboard_English'. Please help.



function CreatePDF() 
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AMDashboard_English");
var sheet = ss.getSheetByName("AMDashboard_English");
Logger.log(sheet.getName());

var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", sheet.getId());

var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls /

var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();

var blobs = [];
var i=0

var response = UrlFetchApp.fetch(
url + url_ext + sheets[i].getSheetId(),
headers: 'Authorization': 'Bearer ' + token

);

blobs[i] = response.getBlob().setName(sheets[i].getName() + '.pdf');
DriveApp.createFile(blobs[i]);
return blobs[i];










share|improve this question



















  • 1





    a workbook ID (SpreadsheetApp.getActive().getId()) and a sheet ID (aka grid ID, SpreadsheetApp.getActive().getSheetByName("some name").getSheetId()) are not the same thing. developers.google.com/sheets/api/guides/concepts#common_terms

    – tehhowch
    Mar 26 at 20:44













0












0








0








I am trying to generate an email with a PDF attachment of a specific sheet, not necessarily the active sheet. I have tried referencing the specific sheet name as well as the number, but to no avail, it chooses sheet 1, titled 'AMDashboard_English'. Please help.



function CreatePDF() 
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AMDashboard_English");
var sheet = ss.getSheetByName("AMDashboard_English");
Logger.log(sheet.getName());

var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", sheet.getId());

var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls /

var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();

var blobs = [];
var i=0

var response = UrlFetchApp.fetch(
url + url_ext + sheets[i].getSheetId(),
headers: 'Authorization': 'Bearer ' + token

);

blobs[i] = response.getBlob().setName(sheets[i].getName() + '.pdf');
DriveApp.createFile(blobs[i]);
return blobs[i];










share|improve this question
















I am trying to generate an email with a PDF attachment of a specific sheet, not necessarily the active sheet. I have tried referencing the specific sheet name as well as the number, but to no avail, it chooses sheet 1, titled 'AMDashboard_English'. Please help.



function CreatePDF() 
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("AMDashboard_English");
var sheet = ss.getSheetByName("AMDashboard_English");
Logger.log(sheet.getName());

var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", sheet.getId());

var url_ext = 'exportFormat=pdf&format=pdf' // export as pdf / csv / xls /

var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();

var blobs = [];
var i=0

var response = UrlFetchApp.fetch(
url + url_ext + sheets[i].getSheetId(),
headers: 'Authorization': 'Bearer ' + token

);

blobs[i] = response.getBlob().setName(sheets[i].getName() + '.pdf');
DriveApp.createFile(blobs[i]);
return blobs[i];







google-apps-script google-sheets export-to-pdf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 20:45









tehhowch

6,6294 gold badges12 silver badges31 bronze badges




6,6294 gold badges12 silver badges31 bronze badges










asked Mar 26 at 15:45









Mitchell WaltzMitchell Waltz

1




1







  • 1





    a workbook ID (SpreadsheetApp.getActive().getId()) and a sheet ID (aka grid ID, SpreadsheetApp.getActive().getSheetByName("some name").getSheetId()) are not the same thing. developers.google.com/sheets/api/guides/concepts#common_terms

    – tehhowch
    Mar 26 at 20:44












  • 1





    a workbook ID (SpreadsheetApp.getActive().getId()) and a sheet ID (aka grid ID, SpreadsheetApp.getActive().getSheetByName("some name").getSheetId()) are not the same thing. developers.google.com/sheets/api/guides/concepts#common_terms

    – tehhowch
    Mar 26 at 20:44







1




1





a workbook ID (SpreadsheetApp.getActive().getId()) and a sheet ID (aka grid ID, SpreadsheetApp.getActive().getSheetByName("some name").getSheetId()) are not the same thing. developers.google.com/sheets/api/guides/concepts#common_terms

– tehhowch
Mar 26 at 20:44





a workbook ID (SpreadsheetApp.getActive().getId()) and a sheet ID (aka grid ID, SpreadsheetApp.getActive().getSheetByName("some name").getSheetId()) are not the same thing. developers.google.com/sheets/api/guides/concepts#common_terms

– tehhowch
Mar 26 at 20:44












2 Answers
2






active

oldest

votes


















0














The url should be of the format below:



https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/export?format=[PDF]&gid=[SHEET_ID]





share|improve this answer






























    0














    I found that the code actually does work as planned. The reason it was not working is that I had another set of code referencing the same var's which apparently confused google scripts. All is well. Thank you.






    share|improve this answer

























      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
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361199%2fselecting-a-specific-sheet-based-off-either-number-from-0-or-name%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The url should be of the format below:



      https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/export?format=[PDF]&gid=[SHEET_ID]





      share|improve this answer



























        0














        The url should be of the format below:



        https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/export?format=[PDF]&gid=[SHEET_ID]





        share|improve this answer

























          0












          0








          0







          The url should be of the format below:



          https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/export?format=[PDF]&gid=[SHEET_ID]





          share|improve this answer













          The url should be of the format below:



          https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/export?format=[PDF]&gid=[SHEET_ID]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 17:14









          TheMasterTheMaster

          13.2k3 gold badges10 silver badges38 bronze badges




          13.2k3 gold badges10 silver badges38 bronze badges























              0














              I found that the code actually does work as planned. The reason it was not working is that I had another set of code referencing the same var's which apparently confused google scripts. All is well. Thank you.






              share|improve this answer



























                0














                I found that the code actually does work as planned. The reason it was not working is that I had another set of code referencing the same var's which apparently confused google scripts. All is well. Thank you.






                share|improve this answer

























                  0












                  0








                  0







                  I found that the code actually does work as planned. The reason it was not working is that I had another set of code referencing the same var's which apparently confused google scripts. All is well. Thank you.






                  share|improve this answer













                  I found that the code actually does work as planned. The reason it was not working is that I had another set of code referencing the same var's which apparently confused google scripts. All is well. Thank you.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 27 at 19:05









                  Mitchell WaltzMitchell Waltz

                  1




                  1



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361199%2fselecting-a-specific-sheet-based-off-either-number-from-0-or-name%23new-answer', 'question_page');

                      );

                      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







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해