Organiza tus páginas con colecciones Guarda y categoriza el contenido según tus preferencias.
El servicio de Presentaciones avanzado te permite acceder a la API de Slides con Apps Script. Este servicio permite que las secuencias de comandos lean y editen contenido en Presentaciones de Google.
Referencia
Para obtener información detallada sobre este servicio, consulta la documentación de referencia de la API de Slides. Al igual que todos los servicios avanzados de Apps Script, el servicio avanzado de Presentaciones usa los mismos objetos, métodos y parámetros que la API pública. Para obtener más información, consulta Cómo se determinan las firmas de métodos.
El siguiente código de ejemplo usa la versión 1 de la API.
Crea una presentación nueva
En el siguiente ejemplo, se muestra cómo crear una presentación nueva con el servicio avanzado de Slides. Es equivalente a la muestra de la receta Crear una presentación nueva.
/** * Create a new presentation. * @return {string} presentation Id. * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/create */functioncreatePresentation(){try{constpresentation=Slides.Presentations.create({'title':'MyNewPresentation'});console.log('Created presentation with ID: '+presentation.presentationId);returnpresentation.presentationId;}catch(e){// TODO (developer) - Handle exceptionconsole.log('Failed with error %s',e.message);}}
Crear una diapositiva nueva
En el siguiente ejemplo, se muestra cómo crear una diapositiva nueva en una presentación, en un índice específico y con un diseño predefinido. Es equivalente a la muestra de la receta Crea una nueva diapositiva.
/** * 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);}}
Leer los ID de objeto de los elementos de la página
En el siguiente ejemplo, se muestra cómo recuperar los IDs de objeto de cada elemento de la página en una diapositiva específica con una máscara de campo. Es equivalente a la muestra de la receta Leer IDs de objetos de elementos de una página.
/** * 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);}}
Agregar un cuadro de texto nuevo
En el siguiente ejemplo, se muestra cómo agregar un nuevo cuadro de texto a una diapositiva y agregarle texto. Es equivalente a la muestra de la receta Cómo agregar un cuadro de texto a una diapositiva.
/** * 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);}}
Dar formato al texto con forma
En el siguiente ejemplo, se muestra cómo dar formato al texto de una forma, actualizar su color y fuente, y subrayar su texto. Es equivalente a la muestra de la receta Formatea texto en una forma o un cuadro de texto.
/** * 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);}}
Prácticas recomendadas
Actualizaciones por lotes
Cuando uses el servicio avanzado de Slides, combina varias solicitudes en un array en lugar de llamar a batchUpdate en un bucle.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-04 (UTC)"],[[["\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 });"]]