/** * Create a new slide. * @param {string} presentationId The presentation to add the slide to. * @return {Object} slide * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate */functioncreateSlide(presentationId){// You can specify the ID to use for the slide, as long as it's unique.constpageId=Utilities.getUuid();constrequests=[{'createSlide':{'objectId':pageId,'insertionIndex':1,'slideLayoutReference':{'predefinedLayout':'TITLE_AND_TWO_COLUMNS'}}}];try{constslide=Slides.Presentations.batchUpdate({'requests':requests},presentationId);console.log('CreatedSlidewithID:'+slide.replies[0].createSlide.objectId);returnslide;}catch(e){// TODO (developer) - Handle Exceptionconsole.log('Failedwitherror%s',e.message);}}
讀取網頁元素物件 ID
以下範例說明如何使用欄位遮罩,擷取特定投影片的每個頁面元素物件 ID。這與從網頁讀取元素物件 ID 的範例食譜相同。
/** * Read page element IDs. * @param {string} presentationId The presentation to read from. * @param {string} pageId The page to read from. * @return {Object} response * @see https://developers.google.com/slides/api/reference/rest/v1/presentations.pages/get */functionreadPageElementIds(presentationId,pageId){// You can use a field mask to limit the data the API retrieves// in a get request, or what fields are updated in an batchUpdate.try{constresponse=Slides.Presentations.Pages.get(presentationId,pageId,{'fields':'pageElements.objectId'});console.log(response);returnresponse;}catch(e){// TODO (developer) - Handle Exceptionconsole.log('Failedwitherror%s',e.message);}}
/** * Add a new text box with text to a page. * @param {string} presentationId The presentation ID. * @param {string} pageId The page ID. * @return {Object} response * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate */functionaddTextBox(presentationId,pageId){// You can specify the ID to use for elements you create,// as long as the ID is unique.constpageElementId=Utilities.getUuid();constrequests=[{'createShape':{'objectId':pageElementId,'shapeType':'TEXT_BOX','elementProperties':{'pageObjectId':pageId,'size':{'width':{'magnitude':150,'unit':'PT'},'height':{'magnitude':50,'unit':'PT'}},'transform':{'scaleX':1,'scaleY':1,'translateX':200,'translateY':100,'unit':'PT'}}}},{'insertText':{'objectId':pageElementId,'text':'MyAddedTextBox','insertionIndex':0}}];try{constresponse=Slides.Presentations.batchUpdate({'requests':requests},presentationId);console.log('CreatedTextboxwithID:'+response.replies[0].createShape.objectId);returnresponse;}catch(e){// TODO (developer) - Handle Exceptionconsole.log('Failedwitherror%s',e.message);}}
/** * Format the text in a shape. * @param {string} presentationId The presentation ID. * @param {string} shapeId The shape ID. * @return {Object} replies * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate */functionformatShapeText(presentationId,shapeId){constrequests=[{'updateTextStyle':{'objectId':shapeId,'fields':'foregroundColor,bold,italic,fontFamily,fontSize,underline','style':{'foregroundColor':{'opaqueColor':{'themeColor':'ACCENT5'}},'bold':true,'italic':true,'underline':true,'fontFamily':'Corsiva','fontSize':{'magnitude':18,'unit':'PT'}},'textRange':{'type':'ALL'}}}];try{constresponse=Slides.Presentations.batchUpdate({'requests':requests},presentationId);returnresponse.replies;}catch(e){// TODO (developer) - Handle Exceptionconsole.log('Failedwitherror%s',e.message);}}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-12-21 (世界標準時間)。"],[[["The Advanced Slides service enables Apps Script to read and edit Google Slides content using the Slides API."],["This advanced service requires enabling before use and utilizes the same structure as the public Slides API."],["Provided code samples demonstrate common tasks like creating presentations and slides, manipulating elements, and formatting text."],["For optimal performance, it is recommended to batch multiple requests within a single `batchUpdate` call instead of using loops."]]],[]]