উন্নত স্লাইড পরিষেবা

অ্যাডভান্সড স্লাইড পরিষেবা আপনাকে Apps স্ক্রিপ্ট ব্যবহার করে স্লাইড API অ্যাক্সেস করতে দেয়। এই পরিষেবাটি স্ক্রিপ্টগুলিকে Google স্লাইডে সামগ্রী পড়তে এবং সম্পাদনা করতে দেয়৷

রেফারেন্স

এই পরিষেবার বিস্তারিত তথ্যের জন্য, স্লাইড API-এর রেফারেন্স ডকুমেন্টেশন দেখুন। Apps Script-এর সমস্ত উন্নত পরিষেবাগুলির মতো, উন্নত স্লাইড পরিষেবাটি পাবলিক API হিসাবে একই বস্তু, পদ্ধতি এবং পরামিতিগুলি ব্যবহার করে৷ আরও তথ্যের জন্য, দেখুন কিভাবে পদ্ধতি স্বাক্ষর নির্ধারণ করা হয়

সমস্যাগুলি রিপোর্ট করতে এবং অন্যান্য সহায়তা পেতে, স্লাইড সমর্থন নির্দেশিকা দেখুন।

কোডের উদাহরণ

নীচের নমুনা কোডটি API-এর সংস্করণ 1 ব্যবহার করে।

একটি নতুন উপস্থাপনা তৈরি করুন

নিম্নলিখিত উদাহরণটি স্লাইডের উন্নত পরিষেবা ব্যবহার করে কীভাবে একটি নতুন উপস্থাপনা তৈরি করতে হয় তা প্রদর্শন করে৷ এটি একটি নতুন উপস্থাপনা রেসিপি নমুনা তৈরি করুন সমতুল্য।

advanced/slides.gs
/**
 * Create a new presentation.
 * @return {string} presentation Id.
 * @see https://developers.google.com/slides/api/reference/rest/v1/presentations/create
 */
function createPresentation() {
  try {
    const presentation =
      Slides.Presentations.create({'title': 'MyNewPresentation'});
    console.log('Created presentation with ID: ' + presentation.presentationId);
    return presentation.presentationId;
  } catch (e) {
    // TODO (developer) - Handle exception
    console.log('Failed with error %s', e.message);
  }
}

একটি নতুন স্লাইড তৈরি করুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি উপস্থাপনায় একটি নতুন স্লাইড তৈরি করতে হয়, একটি নির্দিষ্ট সূচকে এবং পূর্বনির্ধারিত বিন্যাস সহ। এটি একটি নতুন স্লাইড রেসিপি নমুনা তৈরি করুন এর সমতুল্য।

advanced/slides.gs
/**
 * 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
 */
function createSlide(presentationId) {
  // You can specify the ID to use for the slide, as long as it's unique.
  const pageId = Utilities.getUuid();

  const requests = [{
    'createSlide': {
      'objectId': pageId,
      'insertionIndex': 1,
      'slideLayoutReference': {
        'predefinedLayout': 'TITLE_AND_TWO_COLUMNS'
      }
    }
  }];
  try {
    const slide =
      Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
    console.log('Created Slide with ID: ' + slide.replies[0].createSlide.objectId);
    return slide;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log('Failed with error %s', e.message);
  }
}

পৃষ্ঠা উপাদান অবজেক্ট আইডি পড়ুন

নিচের উদাহরণটি দেখায় কিভাবে একটি ফিল্ড মাস্ক ব্যবহার করে একটি নির্দিষ্ট স্লাইডে প্রতিটি পৃষ্ঠার উপাদানের জন্য অবজেক্ট আইডি পুনরুদ্ধার করা যায়। এটি একটি পৃষ্ঠা রেসিপি নমুনা থেকে রিড এলিমেন্ট অবজেক্ট আইডির সমতুল্য।

advanced/slides.gs
/**
 * 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
 */
function readPageElementIds(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 {
    const response = Slides.Presentations.Pages.get(
        presentationId, pageId, {'fields': 'pageElements.objectId'});
    console.log(response);
    return response;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log('Failed with error %s', e.message);
  }
}

একটি নতুন টেক্সট বক্স যোগ করুন

নিচের উদাহরণটি দেখায় কিভাবে একটি স্লাইডে একটি নতুন টেক্সট বক্স যোগ করতে হয় এবং এতে টেক্সট যোগ করতে হয়। এটি একটি স্লাইড রেসিপি নমুনায় একটি পাঠ্য বাক্স যুক্ত করুন এর সমতুল্য।

advanced/slides.gs
/**
 * 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
 */
function addTextBox(presentationId, pageId) {
  // You can specify the ID to use for elements you create,
  // as long as the ID is unique.
  const pageElementId = Utilities.getUuid();

  const requests = [{
    '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 {
    const response =
      Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
    console.log('Created Textbox with ID: ' +
      response.replies[0].createShape.objectId);
    return response;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log('Failed with error %s', e.message);
  }
}

ফর্ম্যাট টেক্সট আকার

নিচের উদাহরণটি দেখায় কিভাবে একটি আকৃতির টেক্সট ফরম্যাট করতে হয়, এর রঙ, ফন্ট আপডেট করে এবং এর টেক্সট আন্ডারলাইন করে। এটি একটি আকার বা টেক্সটবক্স রেসিপি নমুনার ফর্ম্যাট পাঠ্যের সমতুল্য।

advanced/slides.gs
/**
 * 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
 */
function formatShapeText(presentationId, shapeId) {
  const requests = [{
    '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 {
    const response =
      Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
    return response.replies;
  } catch (e) {
    // TODO (developer) - Handle Exception
    console.log('Failed with error %s', e.message);
  }
}

সেরা অনুশীলন

ব্যাচ আপডেট

স্লাইডস অ্যাডভান্সড সার্ভিস ব্যবহার করার সময়, batchUpdate লুপে কল করার পরিবর্তে একটি অ্যারেতে একাধিক অনুরোধ একত্রিত করুন।

করবেন না — একটি লুপে batchUpdate কল করুন।

var titles = ["slide 1", "slide 2"];
for (var i = 0; i < titles.length; i++) {
  Slides.Presentations.batchUpdate(preso, {
    requests: [{
      createSlide: ...
    }]
  });
}

করুন — আপডেটের অ্যারের সাথে batchUpdate কল করুন।

var requests = [];
var titles = ["slide 1", "slide 2"];
for (var i = 0; i < titles.length; i++) {
  requests.push({ createSlide: ... });
}

Slides.Presentations.batchUpdate(preso, {
  requests: requests
});