با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
سرویس Advanced Slides به شما امکان می دهد با استفاده از Apps Script به API Slides دسترسی داشته باشید. این سرویس به اسکریپت ها امکان خواندن و ویرایش محتوا در اسلایدهای Google را می دهد.
مرجع
برای اطلاعات دقیق در مورد این سرویس، به مستندات مرجع برای Slides API مراجعه کنید. مانند همه سرویسهای پیشرفته در Apps Script، سرویس Slides پیشرفته از همان اشیا، روشها و پارامترهای API عمومی استفاده میکند. برای اطلاعات بیشتر، نحوه تعیین امضای روش را ببینید.
/** * 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('Created Slide with ID: '+slide.replies[0].createSlide.objectId);returnslide;}catch(e){// TODO (developer) - Handle Exceptionconsole.log('Failed with error %s',e.message);}}
/** * 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('Failed with error %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':'My Added Text Box','insertionIndex':0}}];try{constresponse=Slides.Presentations.batchUpdate({'requests':requests},presentationId);console.log('Created Textbox with ID: '+response.replies[0].createShape.objectId);returnresponse;}catch(e){// TODO (developer) - Handle Exceptionconsole.log('Failed with error %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('Failed with error %s',e.message);}}
بهترین شیوه ها
به روز رسانی دسته ای
هنگام استفاده از سرویس پیشرفته اسلایدها، به جای فراخوانی batchUpdate در یک حلقه، چندین درخواست را در یک آرایه ترکیب کنید.
انجام ندهید - batchUpdate در یک حلقه فراخوانی کنید.
تاریخ آخرین بهروزرسانی 2025-08-04 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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"]],["تاریخ آخرین بهروزرسانی 2025-08-04 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe Advanced Slides service enables Apps Script to read and edit Google Slides content using the Slides API.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling before use and utilizes the same structure as the public Slides API.\u003c/p\u003e\n"],["\u003cp\u003eProvided code samples demonstrate common tasks like creating presentations and slides, manipulating elements, and formatting text.\u003c/p\u003e\n"],["\u003cp\u003eFor optimal performance, it is recommended to batch multiple requests within a single \u003ccode\u003ebatchUpdate\u003c/code\u003e call instead of using loops.\u003c/p\u003e\n"]]],[],null,["The Advanced Slides service lets you access the [Slides API](/slides) using\nApps Script. This service allows scripts to read and edit content in Google Slides.\n| This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n\nFor detailed information on this service, see the\n[reference documentation](/slides/reference/rest) for the Slides API.\nLike all advanced services in Apps Script, the advanced Slides service uses the\nsame objects, methods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Slides support guide](/slides/support).\n\nSample code\n\nThe sample code below uses [version 1](/slides/reference/rest) of the API.\n\nCreate a new presentation\n\nThe following example demonstrates how to create a new presentation using the\nSlides advanced service. It is equivalent to the\n[Create a new presentation](/slides/samples/presentation#create_a_new_presentation)\nrecipe sample. \nadvanced/slides.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/slides.gs) \n\n```gosu\n/**\n * Create a new presentation.\n * @return {string} presentation Id.\n * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/create\n */\nfunction createPresentation() {\n try {\n const presentation =\n Slides.Presentations.create({'title': 'MyNewPresentation'});\n console.log('Created presentation with ID: ' + presentation.presentationId);\n return presentation.presentationId;\n } catch (e) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', e.message);\n }\n}\n```\n\nCreate a new slide\n\nThe following example demonstrates how to create a new slide in a presentation,\nat a specific index and with predefined layout. It is equivalent to the\n[Create a new slide](/slides/samples/slides#create_a_new_slide)\nrecipe sample. \nadvanced/slides.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/slides.gs) \n\n```gosu\n/**\n * Create a new slide.\n * @param {string} presentationId The presentation to add the slide to.\n * @return {Object} slide\n * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate\n */\nfunction createSlide(presentationId) {\n // You can specify the ID to use for the slide, as long as it's unique.\n const pageId = Utilities.getUuid();\n\n const requests = [{\n 'createSlide': {\n 'objectId': pageId,\n 'insertionIndex': 1,\n 'slideLayoutReference': {\n 'predefinedLayout': 'TITLE_AND_TWO_COLUMNS'\n }\n }\n }];\n try {\n const slide =\n Slides.Presentations.batchUpdate({'requests': requests}, presentationId);\n console.log('Created Slide with ID: ' + slide.replies[0].createSlide.objectId);\n return slide;\n } catch (e) {\n // TODO (developer) - Handle Exception\n console.log('Failed with error %s', e.message);\n }\n}\n```\n\nRead page element object IDs\n\nThe following example demonstrates how to retrieve the object IDs for every page\nelement on a specific slide using a field mask. It is equivalent to the\n[Read element object IDs from a page](/slides/samples/reading#read_element_object_ids_from_a_page)\nrecipe sample. \nadvanced/slides.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/slides.gs) \n\n```gosu\n/**\n * Read page element IDs.\n * @param {string} presentationId The presentation to read from.\n * @param {string} pageId The page to read from.\n * @return {Object} response\n * @see https://developers.google.com/slides/api/reference/rest/v1/presentations.pages/get\n */\nfunction readPageElementIds(presentationId, pageId) {\n // You can use a field mask to limit the data the API retrieves\n // in a get request, or what fields are updated in an batchUpdate.\n try {\n const response = Slides.Presentations.Pages.get(\n presentationId, pageId, {'fields': 'pageElements.objectId'});\n console.log(response);\n return response;\n } catch (e) {\n // TODO (developer) - Handle Exception\n console.log('Failed with error %s', e.message);\n }\n}\n```\n\nAdd a new text box\n\nThe following example demonstrates how to add a new text box to a slide and add\ntext to it. It is equivalent to the\n[Add a text box to a slide](/slides/samples/writing#add_a_text_box_to_a_slide)\nrecipe sample. \nadvanced/slides.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/slides.gs) \n\n```gosu\n/**\n * Add a new text box with text to a page.\n * @param {string} presentationId The presentation ID.\n * @param {string} pageId The page ID.\n * @return {Object} response\n * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate\n */\nfunction addTextBox(presentationId, pageId) {\n // You can specify the ID to use for elements you create,\n // as long as the ID is unique.\n const pageElementId = Utilities.getUuid();\n\n const requests = [{\n 'createShape': {\n 'objectId': pageElementId,\n 'shapeType': 'TEXT_BOX',\n 'elementProperties': {\n 'pageObjectId': pageId,\n 'size': {\n 'width': {\n 'magnitude': 150,\n 'unit': 'PT'\n },\n 'height': {\n 'magnitude': 50,\n 'unit': 'PT'\n }\n },\n 'transform': {\n 'scaleX': 1,\n 'scaleY': 1,\n 'translateX': 200,\n 'translateY': 100,\n 'unit': 'PT'\n }\n }\n }\n }, {\n 'insertText': {\n 'objectId': pageElementId,\n 'text': 'My Added Text Box',\n 'insertionIndex': 0\n }\n }];\n try {\n const response =\n Slides.Presentations.batchUpdate({'requests': requests}, presentationId);\n console.log('Created Textbox with ID: ' +\n response.replies[0].createShape.objectId);\n return response;\n } catch (e) {\n // TODO (developer) - Handle Exception\n console.log('Failed with error %s', e.message);\n }\n}\n```\n\nFormat shape text\n\nThe following example demonstrates how to format a shape's text, updating its\ncolor, font and underlining its text. It is equivalent to the\n[Format text in a shape or textbox](/slides/samples/elements#format_text_in_a_shape_or_textbox)\nrecipe sample. \nadvanced/slides.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/slides.gs) \n\n```gosu\n/**\n * Format the text in a shape.\n * @param {string} presentationId The presentation ID.\n * @param {string} shapeId The shape ID.\n * @return {Object} replies\n * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate\n */\nfunction formatShapeText(presentationId, shapeId) {\n const requests = [{\n 'updateTextStyle': {\n 'objectId': shapeId,\n 'fields': 'foregroundColor,bold,italic,fontFamily,fontSize,underline',\n 'style': {\n 'foregroundColor': {\n 'opaqueColor': {\n 'themeColor': 'ACCENT5'\n }\n },\n 'bold': true,\n 'italic': true,\n 'underline': true,\n 'fontFamily': 'Corsiva',\n 'fontSize': {\n 'magnitude': 18,\n 'unit': 'PT'\n }\n },\n 'textRange': {\n 'type': 'ALL'\n }\n }\n }];\n try {\n const response =\n Slides.Presentations.batchUpdate({'requests': requests}, presentationId);\n return response.replies;\n } catch (e) {\n // TODO (developer) - Handle Exception\n console.log('Failed with error %s', e.message);\n }\n}\n```\n\nBest Practices\n\nBatch Updates\n\nWhen using the Slides Advanced Service, combine multiple requests in an array\nrather than calling `batchUpdate` in a loop.\n\nDon't --- Call `batchUpdate` in a loop. \n\n var titles = [\"slide 1\", \"slide 2\"];\n for (var i = 0; i \u003c titles.length; i++) {\n Slides.Presentations.batchUpdate(preso, {\n requests: [{\n createSlide: ...\n }]\n });\n }\n\nDo --- Call `batchUpdate` with an array of\nupdates. \n\n var requests = [];\n var titles = [\"slide 1\", \"slide 2\"];\n for (var i = 0; i \u003c titles.length; i++) {\n requests.push({ createSlide: ... });\n }\n\n Slides.Presentations.batchUpdate(preso, {\n requests: requests\n });"]]