تنظيم صفحاتك في مجموعات يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك خدمة "العروض التقديمية المتقدّمة" الوصول إلى Slides API باستخدام Apps Script. تسمح هذه الخدمة للبرامج النصية بقراءة المحتوى وتعديله في "العروض التقديمية من Google".
مراجع
للحصول على معلومات مفصّلة حول هذه الخدمة، يُرجى الاطّلاع على المستندات المرجعية الخاصة بواجهة برمجة التطبيقات Slides API. مثل جميع الخدمات المتقدّمة في "برمجة التطبيقات"، تستخدم خدمة "العروض التقديمية" المتقدّمة الكائنات والطُرق والمعلَمات نفسها المستخدَمة في واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، اطّلِع على كيفية تحديد تواقيع الطرق.
يستخدم نموذج الرمز البرمجي أدناه الإصدار 1 من واجهة برمجة التطبيقات.
إنشاء عرض تقديمي جديد
يوضّح المثال التالي كيفية إنشاء عرض تقديمي جديد باستخدام الخدمة المتقدّمة في "العروض التقديمية من Google". وهو يعادل نموذج الوصفة إنشاء عرض تقديمي جديد.
/** * 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);}}
أفضل الممارسات
التعديلات المجمّعة
عند استخدام خدمة Slides المتقدّمة، ادمِج طلبات متعددة في مصفوفة بدلاً من استدعاء 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 });"]]