Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Z tej strony dowiesz się, jak dodać slajdy do istniejącej prezentacji w Prezentacji Google.
Prezentacje
Każda strona prezentacji w Prezentacjach to slajd.
Aby dodać slajd do prezentacji, musisz znać identyfikator prezentacji. Identyfikator prezentacji możesz znaleźć, otwierając ją w Prezentacjach i sprawdzając adres URL:
Aby dodać slajd, użyj metody batchUpdate() z identyfikatorem prezentacji i uwzględnij w ciele żądania parametr CreateSlideRequest. Identyfikator nowego slajdu jest zwracany w treści odpowiedzi.
Przykład
Ten przykład pokazuje, jak dodać slajdu do prezentacji. Wszystkie pola w sekcji
CreateSlideRequest
są opcjonalne. W tym przykładzie tworzymy drugą stronę z układem TITLE_AND_TWO_COLUMNS i jawnym identyfikatorem obiektu.
/** * Creates a slide * @param {string} presentationId * @param {string} pageId * @returns {*} */functioncreateSlide(presentationId,pageId){// See Presentation.insertSlide(...) to learn how to add a slide using SlidesApp.// http://developers.google.com/apps-script/reference/slides/presentation#appendslidelayoutconstrequests=[{createSlide:{objectId:pageId,insertionIndex:'1',slideLayoutReference:{predefinedLayout:'TITLE_AND_TWO_COLUMNS'}}}];// If you wish to populate the slide with elements, add element create requests here,// using the pageId.// Execute the request.try{constcreateSlideResponse=Slides.Presentations.batchUpdate({requests:requests},presentationId);console.log('CreatedslidewithID:%s',createSlideResponse.replies[0].createSlide.objectId);returncreateSlideResponse;}catch(err){// TODO (Developer) - Handle exceptionconsole.log('Failedwitherror:%s',err.error);}};
// Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layout// and the ID "MyNewSlide_001".slideId:="MyNewSlide_001"requests:=[]*slides.Request{{
CreateSlide: &slides.CreateSlideRequest{
ObjectId: slideId,
InsertionIndex: 1,
SlideLayoutReference: &slides.LayoutReference{
PredefinedLayout: "TITLE_AND_TWO_COLUMNS",
},
},
}}// If you wish to populate the slide with elements, add create requests here,// using the slide ID specified above.// Execute the request.body:=&slides.BatchUpdatePresentationRequest{Requests:requests,}response,err:=slidesService.Presentations.BatchUpdate(presentationId,body).Do()iferr!=nil{log.Fatalf("Unable to create slide. %v",err)}fmt.Printf("Created slide with ID: %s",response.Replies[0].CreateSlide.ObjectId)
importcom.google.api.client.googleapis.json.GoogleJsonResponseException;importcom.google.api.client.googleapis.json.GoogleJsonError;importcom.google.api.client.http.HttpRequestInitializer;importcom.google.api.client.http.javanet.NetHttpTransport;importcom.google.api.client.json.gson.GsonFactory;importcom.google.api.services.slides.v1.Slides;importcom.google.api.services.slides.v1.SlidesScopes;importcom.google.api.services.slides.v1.model.BatchUpdatePresentationRequest;importcom.google.api.services.slides.v1.model.BatchUpdatePresentationResponse;importcom.google.api.services.slides.v1.model.CreateSlideRequest;importcom.google.api.services.slides.v1.model.CreateSlideResponse;importcom.google.api.services.slides.v1.model.LayoutReference;importcom.google.api.services.slides.v1.model.Request;importcom.google.auth.http.HttpCredentialsAdapter;importcom.google.auth.oauth2.GoogleCredentials;importjava.io.IOException;importjava.util.ArrayList;importjava.util.Collections;importjava.util.List;/* Class to demonstrate the use of Create Slides API */publicclassCreateSlide{/** * Creates a new slide. * * @param presentationId - id of the presentation. * @return slide id * @throws IOException - if credentials file not found. */publicstaticBatchUpdatePresentationResponsecreateSlide(StringpresentationId)throwsIOException{/* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application. */GoogleCredentialscredentials=GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(SlidesScopes.PRESENTATIONS));HttpRequestInitializerrequestInitializer=newHttpCredentialsAdapter(credentials);// Create the slides API clientSlidesservice=newSlides.Builder(newNetHttpTransport(),GsonFactory.getDefaultInstance(),requestInitializer).setApplicationName("Slides samples").build();// Add a slide at index 1 using the predefined "TITLE_AND_TWO_COLUMNS" layoutList<Request>requests=newArrayList<>();StringslideId="MyNewSlide_001";BatchUpdatePresentationResponseresponse=null;try{requests.add(newRequest().setCreateSlide(newCreateSlideRequest().setObjectId(slideId).setInsertionIndex(1).setSlideLayoutReference(newLayoutReference().setPredefinedLayout("TITLE_AND_TWO_COLUMNS"))));// If you wish to populate the slide with elements, add create requests here,// using the slide ID specified above.// Execute the request.BatchUpdatePresentationRequestbody=newBatchUpdatePresentationRequest().setRequests(requests);response=service.presentations().batchUpdate(presentationId,body).execute();CreateSlideResponsecreateSlideResponse=response.getReplies().get(0).getCreateSlide();// Prints the slide id.System.out.println("Created slide with ID: "+createSlideResponse.getObjectId());}catch(GoogleJsonResponseExceptione){// TODO(developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==400){System.out.printf(" Id '%s' should be unique among all pages and page elements.\n",presentationId);}elseif(error.getCode()==404){System.out.printf("Presentation not found with id '%s'.\n",presentationId);}else{throwe;}}returnresponse;}}
functioncreateSlide(presentationId,pageId,callback){constrequests=[{createSlide:{objectId:pageId,insertionIndex:'1',slideLayoutReference:{predefinedLayout:'TITLE_AND_TWO_COLUMNS',},},},];// If you wish to populate the slide with elements, add element create requests here,// using the pageId.// Execute the request.try{gapi.client.slides.presentations.batchUpdate({presentationId:presentationId,requests:requests,}).then((createSlideResponse)=>{constobjectId=createSlideResponse.result.replies[0].createSlide.objectId;console.log(`Created slide with ID: ${objectId}`);if(callback)callback(createSlideResponse);});}catch(err){document.getElementById('content').innerText=err.message;return;}}
/** * Creates a new slide in a presentation. * @param {string} presentationId The presentation ID. * @param {string} pageId The object ID for the new slide. */asyncfunctioncreateSlide(presentationId,pageId){const{GoogleAuth}=require('google-auth-library');const{google}=require('googleapis');constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/presentations',});constservice=google.slides({version:'v1',auth});constrequests=[{createSlide:{objectId:pageId,insertionIndex:'1',slideLayoutReference:{predefinedLayout:'TITLE_AND_TWO_COLUMNS',},},},];// If you wish to populate the slide with elements, add element create requests here,// using the pageId.// Execute the request.try{constres=awaitservice.presentations.batchUpdate({presentationId,resource:{requests,},});console.log(`Created slide with ID: ${res.data.replies[0].createSlide.objectId}`,);returnres;}catch(err){// TODO (developer) - handle exceptionthrowerr;}}
importgoogle.authfromgoogleapiclient.discoveryimportbuildfromgoogleapiclient.errorsimportHttpErrordefcreate_slide(presentation_id,page_id):""" Creates the Presentation the user has access to. Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for the application.\n """creds,_=google.auth.default()# pylint: disable=maybe-no-membertry:service=build("slides","v1",credentials=creds)# Add a slide at index 1 using the predefined# 'TITLE_AND_TWO_COLUMNS' layout and the ID page_id.requests=[{"createSlide":{"objectId":page_id,"insertionIndex":"1","slideLayoutReference":{"predefinedLayout":"TITLE_AND_TWO_COLUMNS"},}}]# If you wish to populate the slide with elements,# add element create requests here, using the page_id.# Execute the request.body={"requests":requests}response=(service.presentations().batchUpdate(presentationId=presentation_id,body=body).execute())create_slide_response=response.get("replies")[0].get("createSlide")print(f"Created slide with ID:{(create_slide_response.get('objectId'))}")exceptHttpErroraserror:print(f"An error occurred: {error}")print("Slides not created")returnerrorreturnresponseif__name__=="__main__":# Put the presentation_id, Page_id of slides whose list needs# to be submitted.create_slide("12SQU9Ik-ShXecJoMtT-LlNwEPiFR7AadnxV2KiBXCnE","My4ndpage")
body=Google::Apis::SlidesV1::Presentation.newrequests=[{create_slide:{object_id_prop:page_id,insertion_index:'1',slide_layout_reference:{predefined_layout:'TITLE_AND_TWO_COLUMNS'}}}]# If you wish to populate the slide with elements, add element create requests here,# using the page_id.# Execute the request.req=Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests:requests)response=slides_service.batch_update_presentation(presentation_id,req)create_slide_response=response.replies[0].create_slideputs"Created slide with ID: #{create_slide_response.object_id}"
Po utworzeniu slajdu możesz dodać do niego tekst i kształty.
Wypełnianie obiektów zastępczych
Szablony zwykle zawierają kształty zastępcze, które są kopiowane na slajd podczas jego tworzenia. CreateSlideRequest umożliwia określenie identyfikatorów obiektów używanych w tych skopiowanych zmiennych za pomocą pola placeholderIdMappings. Dzięki temu możesz modyfikować skopiowane placeholdery w tym samym żądaniu batchUpdate, co poprawia wydajność i oszczędza limit. Więcej informacji znajdziesz w pliku CreateSlideRequest.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2024-12-21 UTC."],[[["This page provides instructions on adding new slides to existing Google Slides presentations."],["You need the presentation ID to add a slide, which can be found in the presentation's URL."],["The `batchUpdate()` method and `CreateSlideRequest` are used to add slides, with the new slide's ID returned in the response."],["Slides can be further customized by adding text, shapes, and filling in placeholders after creation."],["The `placeholderIdMappings` field in `CreateSlideRequest` allows for efficient modification of copied placeholders during the slide creation process."]]],[]]