অন্যান্য স্প্রেডশীটে ম্যাক্রো কপি করুন

কোডিং লেভেল : ইন্টারমিডিয়েট
সময়কাল : 30 মিনিট
প্রকল্পের ধরন : Google Workspace অ্যাড-অন

উদ্দেশ্য

  • বুঝুন সমাধান কি করে।
  • সমাধানের মধ্যে অ্যাপস স্ক্রিপ্ট পরিষেবাগুলি কী করে তা বুঝুন।
  • পরিবেশ স্থাপন করুন।
  • স্ক্রিপ্ট সেট আপ করুন।
  • স্ক্রিপ্ট চালান।

এই সমাধান সম্পর্কে

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

শেয়ার ম্যাক্রো গুগল ওয়ার্কস্পেস অ্যাড-অনের স্ক্রিনশট

কিভাবে এটা কাজ করে

স্ক্রিপ্টটি অ্যাপস স্ক্রিপ্ট প্রকল্পটিকে অনুলিপি করে যা আসল স্প্রেডশীটের সাথে আবদ্ধ এবং ব্যবহারকারী-নির্দিষ্ট স্প্রেডশীটে আবদ্ধ একটি ডুপ্লিকেট অ্যাপস স্ক্রিপ্ট প্রকল্প তৈরি করে।

অ্যাপস স্ক্রিপ্ট পরিষেবা

এই সমাধানটি নিম্নলিখিত পরিষেবাগুলি ব্যবহার করে:

পূর্বশর্ত

এই নমুনা ব্যবহার করতে, আপনার নিম্নলিখিত পূর্বশর্ত প্রয়োজন:

আপনার পরিবেশ সেট আপ করুন

Google ক্লাউড কনসোলে আপনার ক্লাউড প্রকল্প খুলুন

যদি এটি ইতিমধ্যে খোলা না থাকে, তাহলে ক্লাউড প্রকল্পটি খুলুন যা আপনি এই নমুনার জন্য ব্যবহার করতে চান:

  1. Google ক্লাউড কনসোলে, একটি প্রকল্প নির্বাচন করুন পৃষ্ঠাতে যান।

    একটি ক্লাউড প্রকল্প নির্বাচন করুন

  2. আপনি যে Google ক্লাউড প্রকল্পটি ব্যবহার করতে চান সেটি নির্বাচন করুন। অথবা, প্রকল্প তৈরি করুন ক্লিক করুন এবং অন-স্ক্রীন নির্দেশাবলী অনুসরণ করুন। আপনি যদি একটি Google ক্লাউড প্রকল্প তৈরি করেন, তাহলে আপনাকে প্রকল্পটির জন্য বিলিং চালু করতে হতে পারে।

Google Apps Script API চালু করুন

এই কুইকস্টার্টটি Google Apps Script API ব্যবহার করে।

Google API ব্যবহার করার আগে, আপনাকে একটি Google ক্লাউড প্রকল্পে সেগুলি চালু করতে হবে। আপনি একটি একক Google ক্লাউড প্রকল্পে এক বা একাধিক API চালু করতে পারেন৷

Google Workspace অ্যাড-অনগুলির জন্য একটি সম্মতি স্ক্রিন কনফিগারেশন প্রয়োজন। আপনার অ্যাড-অনের OAuth সম্মতি স্ক্রীন কনফিগার করলে তা নির্ধারণ করে যে Google ব্যবহারকারীদের কাছে কী প্রদর্শন করে।

  1. Google ক্লাউড কনসোলে, মেনু > API এবং পরিষেবা > OAuth সম্মতি স্ক্রীনে যান।

    OAuth সম্মতি স্ক্রিনে যান

  2. ব্যবহারকারীর প্রকারের জন্য অভ্যন্তরীণ নির্বাচন করুন, তারপরে তৈরি করুন ক্লিক করুন।
  3. অ্যাপ রেজিস্ট্রেশন ফর্মটি পূরণ করুন, তারপর সংরক্ষণ করুন এবং চালিয়ে যান-এ ক্লিক করুন।
  4. আপাতত, আপনি স্কোপ যোগ করা এড়িয়ে যেতে পারেন এবং সেভ এবং কন্টিনিউ এ ক্লিক করতে পারেন। ভবিষ্যতে, যখন আপনি আপনার Google Workspace সংস্থার বাইরে ব্যবহারের জন্য একটি অ্যাপ তৈরি করবেন, তখন আপনাকে অবশ্যই ব্যবহারকারীর ধরন পরিবর্তন করে External তে পরিবর্তন করতে হবে এবং তারপরে, আপনার অ্যাপের প্রয়োজনীয় অনুমোদনের সুযোগ যোগ করতে হবে।

  5. আপনার অ্যাপ নিবন্ধন সারাংশ পর্যালোচনা করুন. পরিবর্তন করতে, সম্পাদনা ক্লিক করুন। অ্যাপ নিবন্ধন ঠিক আছে বলে মনে হলে, ড্যাশবোর্ডে ফিরে যান ক্লিক করুন।

স্ক্রিপ্ট সেট আপ করুন

অ্যাপস স্ক্রিপ্ট প্রকল্প তৈরি করুন

  1. শেয়ার এ ম্যাক্রো অ্যাপস স্ক্রিপ্ট প্রকল্প খুলতে নিম্নলিখিত বোতামে ক্লিক করুন।
    প্রকল্প খুলুন
  2. ওভারভিউ ক্লিক করুন।
  3. ওভারভিউ পৃষ্ঠায়, একটি অনুলিপি তৈরি করুন ক্লিক করুন একটি অনুলিপি তৈরি করার জন্য আইকন .

ক্লাউড প্রকল্প নম্বর কপি করুন

  1. Google ক্লাউড কনসোলে, মেনু > IAM & Admin > সেটিংসে যান।

    IAM এবং অ্যাডমিন সেটিংসে যান

  2. প্রকল্প নম্বর ক্ষেত্রে, মানটি অনুলিপি করুন।

অ্যাপস স্ক্রিপ্ট প্রকল্পের ক্লাউড প্রকল্প সেট করুন

  1. আপনার অনুলিপি করা Apps স্ক্রিপ্ট প্রকল্পে, প্রকল্প সেটিংস ক্লিক করুন প্রকল্প সেটিংসের জন্য আইকন .
  2. Google ক্লাউড প্ল্যাটফর্ম (GCP) প্রকল্পের অধীনে, প্রকল্প পরিবর্তন করুন ক্লিক করুন।
  3. GCP প্রকল্প নম্বরে , Google ক্লাউড প্রকল্প নম্বর পেস্ট করুন।
  4. সেট প্রকল্প ক্লিক করুন.

একটি পরীক্ষা স্থাপনা ইনস্টল করুন

  1. আপনার অনুলিপি করা Apps স্ক্রিপ্ট প্রকল্পে, সম্পাদক ক্লিক করুন।
  2. UI.gs ফাইলটি খুলুন এবং রান এ ক্লিক করুন। অনুরোধ করা হলে, স্ক্রিপ্ট অনুমোদন করুন.
  3. Deploy > Test deployments এ ক্লিক করুন।
  4. ইনস্টল > সম্পন্ন ক্লিক করুন।

ম্যাক্রো স্ক্রিপ্ট এবং স্প্রেডশীট তথ্য পান

  1. একটি পত্রক স্প্রেডশীট খুলুন যাতে একটি ম্যাক্রো রয়েছে এবং আপনার সম্পাদনা করার অনুমতি রয়েছে৷ একটি নমুনা স্প্রেডশীট ব্যবহার করতে, নমুনা ম্যাক্রো স্প্রেডশীটের একটি অনুলিপি তৈরি করুন
  2. এক্সটেনশন > অ্যাপস স্ক্রিপ্টে ক্লিক করুন।
  3. অ্যাপস স্ক্রিপ্ট প্রকল্পে, প্রকল্প সেটিংস ক্লিক করুন প্রকল্প সেটিংসের জন্য আইকন .
  4. স্ক্রিপ্ট আইডির অধীনে, অনুলিপি ক্লিক করুন।
  5. পরবর্তী ধাপে ব্যবহারের জন্য স্ক্রিপ্ট আইডি আলাদা করে রাখুন।
  6. একটি নতুন স্প্রেডশীট খুলুন বা তৈরি করুন যেখানে আপনি ম্যাক্রো যোগ করতে চান। আপনার স্প্রেডশীট সম্পাদনা করার অনুমতি থাকতে হবে।
  7. স্প্রেডশীট URL অনুলিপি করুন এবং পরবর্তী ধাপে ব্যবহারের জন্য এটিকে আলাদা করে রাখুন।

স্ক্রিপ্ট চালান

আপনার ড্যাশবোর্ড সেটিংসে Google Apps Script API চালু আছে তা নিশ্চিত করুন। আপনার স্ক্রিপ্ট চালানোর জন্য নিম্নলিখিত বিভাগে পদক্ষেপ নিন।

ম্যাক্রো কপি করুন

  1. পত্রক-এ, ডান সাইডবারে, শেয়ার ম্যাক্রো অ্যাড-অন খুলুন একটি অনুলিপি তৈরি করার জন্য আইকন .
  2. সোর্স ম্যাক্রোর অধীনে, স্ক্রিপ্ট আইডি পেস্ট করুন।
  3. টার্গেট স্প্রেডশীটের অধীনে, স্প্রেডশীট URL পেস্ট করুন।
  4. শেয়ার ম্যাক্রোতে ক্লিক করুন।
  5. অ্যাক্সেস অনুমোদন এবং অ্যাড-অন অনুমোদন ক্লিক করুন.
  6. ধাপ 2-4 পুনরাবৃত্তি করুন.

অনুলিপি করা ম্যাক্রো খুলুন

  1. যদি এটি ইতিমধ্যে খোলা না থাকে, তাহলে যে স্প্রেডশীটটিতে আপনি ম্যাক্রোটি কপি করেছেন সেটি খুলুন।
  2. এক্সটেনশন > অ্যাপস স্ক্রিপ্টে ক্লিক করুন।
  3. আপনি যদি অনুলিপি করা অ্যাপস স্ক্রিপ্ট প্রকল্পটি দেখতে না পান তবে নিশ্চিত করুন যে ড্যাশবোর্ড সেটিংসে Google Apps স্ক্রিপ্ট API চালু আছে এবং ম্যাক্রো অনুলিপি করুন এর অধীনে তালিকাভুক্ত পদক্ষেপগুলি পুনরাবৃত্তি করুন।

কোড পর্যালোচনা করুন

এই সমাধানের জন্য অ্যাপস স্ক্রিপ্ট কোড পর্যালোচনা করতে, নীচের উৎস কোড দেখুন ক্লিক করুন:

সোর্স কোড দেখুন

Code.gs

সমাধান/add-on/share-macro/Code.js
// To learn how to use this script, refer to the documentation:
// https://developers.devsite.corp.google.com/apps-script/add-ons/share-macro

/*
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
 * Uses Apps Script API to copy source Apps Script project 
 * to destination Google Spreadsheet container.
 * 
 * @param {string} sourceScriptId - Script ID of the source project.
 * @param {string} targetSpreadsheetUrl - URL if the target spreadsheet.
 * @return {Card[]} - Card indicating successful copy.
 */
function shareMacro_(sourceScriptId, targetSpreadsheetUrl) {

  // Gets the source project content using the Apps Script API.
  const sourceProject = APPS_SCRIPT_API.get(sourceScriptId);
  const sourceFiles = APPS_SCRIPT_API.getContent(sourceScriptId);

  // Opens the target spreadsheet and gets its ID.
  const parentSSId = SpreadsheetApp.openByUrl(targetSpreadsheetUrl).getId();

  // Creates an Apps Script project that's bound to the target spreadsheet.
  const targetProjectObj = APPS_SCRIPT_API.create(sourceProject.title, parentSSId);

  // Updates the Apps Script project with the source project content.
  APPS_SCRIPT_API.updateContent(targetProjectObj.scriptId, sourceFiles);

}

/**
 * Function that encapsulates Apps Script API project manipulation. 
*/
const APPS_SCRIPT_API = {
  accessToken: ScriptApp.getOAuthToken(),

  /* APPS_SCRIPT_API.get
   * Gets Apps Script source project.
   * @param {string} scriptId - Script ID of the source project.
   * @return {Object} - JSON representation of source project.
   */
  get: function (scriptId) {
    const url = ('https://script.googleapis.com/v1/projects/' + scriptId);
    const options = {
      "method": 'get',
      "headers": {
        "Authorization": "Bearer " + this.accessToken
      },
      "muteHttpExceptions": true,
    };
    const res = UrlFetchApp.fetch(url, options);
    if (res.getResponseCode() == 200) {
      return JSON.parse(res);
    } else {
      console.log('An error occurred gettting the project details');
      console.log(res.getResponseCode());
      console.log(res.getContentText());
      console.log(res);
      return false;
    }
  },

  /* APPS_SCRIPT_API.create
   * Creates new Apps Script project in the target spreadsheet.
   * @param {string} title - Name of Apps Script project.
   * @param {string} parentId - Internal ID of target spreadsheet.
   * @return {Object} - JSON representation completed project creation.
   */
  create: function (title, parentId) {
    const url = 'https://script.googleapis.com/v1/projects';
    const options = {
      "headers": {
        "Authorization": "Bearer " + this.accessToken,
        "Content-Type": "application/json"
      },
      "muteHttpExceptions": true,
      "method": "POST",
      "payload": { "title": title }
    }
    if (parentId) {
      options.payload.parentId = parentId;
    }
    options.payload = JSON.stringify(options.payload);
    let res = UrlFetchApp.fetch(url, options);
    if (res.getResponseCode() == 200) {
      res = JSON.parse(res);
      return res;
    } else {
      console.log("An error occurred while creating the project");
      console.log(res.getResponseCode());
      console.log(res.getContentText());
      console.log(res);
      return false;
    }
  },
   /* APPS_SCRIPT_API.getContent
   * Gets the content of the source Apps Script project.
   * @param {string} scriptId - Script ID of the source project.
   * @return {Object} - JSON representation of Apps Script project content.
   */
   getContent: function (scriptId) {
    const url = "https://script.googleapis.com/v1/projects/" + scriptId + "/content";
    const options = {
      "method": 'get',
      "headers": {
        "Authorization": "Bearer " + this.accessToken
      },
      "muteHttpExceptions": true,
    };
    let res = UrlFetchApp.fetch(url, options);
    if (res.getResponseCode() == 200) {
      res = JSON.parse(res);
      return res['files'];
    } else {
      console.log('An error occurred obtaining the content from the source script');
      console.log(res.getResponseCode());
      console.log(res.getContentText());
      console.log(res);
      return false;
    }
  },

  /* APPS_SCRIPT_API.updateContent
   * Updates (copies) content from source to target Apps Script project.
   * @param {string} scriptId - Script ID of the source project.
   * @param {Object} files - JSON representation of Apps Script project content.
   * @return {boolean} - Result status of the function.
   */
  updateContent: function (scriptId, files) {
    const url = "https://script.googleapis.com/v1/projects/" + scriptId + "/content";
    const options = {
      "method": 'put',
      "headers": {
        "Authorization": "Bearer " + this.accessToken
      },
      "contentType": "application/json",
      "payload": JSON.stringify({ "files": files }),
      "muteHttpExceptions": true,
    };
    let res = UrlFetchApp.fetch(url, options);
    if (res.getResponseCode() == 200) {
      return true;
    } else {
      console.log(`An error occurred updating content of script ${scriptId}`);
      console.log(res.getResponseCode());
      console.log(res.getContentText());
      console.log(res);
      return false;
    }
  }
}

UI.gs

সমাধান/add-on/share-macro/UI.js
/**
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Change application logo here (and in manifest) as desired.
const ADDON_LOGO = 'https://www.gstatic.com/images/branding/product/2x/apps_script_48dp.png';

/**
 * Callback function for rendering the main card.
 * @return {CardService.Card} The card to show the user.
 */
function onHomepage(e) {
  return createSelectionCard(e);
}

/**
 * Builds the primary card interface used to collect user inputs.
 * 
 * @param {Object} e - Add-on event object.
 * @param {string} sourceScriptId - Script ID of the source project.
 * @param {string} targetSpreadsheetUrl - URL of the target spreadsheet.
 * @param {string[]} errors - Array of error messages. 
 * 
 * @return {CardService.Card} The card to show to the user for inputs.
 */
function createSelectionCard(e, sourceScriptId, targetSpreadsheetUrl, errors) {

  // Configures card header.
  let cardHeader = CardService.newCardHeader()
    .setTitle('Share macros with other spreadheets!')
    .setImageUrl(ADDON_LOGO)
    .setImageStyle(CardService.ImageStyle.SQUARE);

  // If form errors exist, configures section with error messages.
  let showErrors = false;

  if (errors && errors.length) {
    showErrors = true;
    let msg = errors.reduce((str, err) => `${str}• ${err}<br>`, '');
    msg = `<b>Form submission errors:</b><br><font color="#ba0000">${msg}</font>`;

    // Builds error message section.
    sectionErrors = CardService.newCardSection()
      .addWidget(CardService.newDecoratedText()
        .setText(msg)
        .setWrapText(true));
  }

  // Configures source project section.
  let sectionSource = CardService.newCardSection()
    .addWidget(CardService.newDecoratedText()
      .setText('<b>Source macro</b><br>The Apps Script project to copy'))

    .addWidget(CardService.newTextInput()
      .setFieldName('sourceScriptId')
      .setValue(sourceScriptId || '')
      .setTitle('Script ID of the source macro')
      .setHint('You must have at least edit permission for the source spreadsheet to access its script project'))

    .addWidget(CardService.newTextButton()
      .setText('Find the script ID')
      .setOpenLink(CardService.newOpenLink()
        .setUrl('https://developers.google.com/apps-script/api/samples/execute')
        .setOpenAs(CardService.OpenAs.FULL_SIZE)
        .setOnClose(CardService.OnClose.NOTHING)));

  // Configures target spreadsheet section.
  let sectionTarget = CardService.newCardSection()
    .addWidget(CardService.newDecoratedText()
      .setText('<b>Target spreadsheet</b>'))

    .addWidget(CardService.newTextInput()
      .setFieldName('targetSpreadsheetUrl')
      .setValue(targetSpreadsheetUrl || '')
      .setHint('You must have at least edit permission for the target spreadsheet')
      .setTitle('Target spreadsheet URL'));

  // Configures help section.
  let sectionHelp = CardService.newCardSection()
    .addWidget(CardService.newDecoratedText()
      .setText('<b><font color=#c80000>NOTE: </font></b>' +
        'The Apps Script API must be turned on.')
      .setWrapText(true))

    .addWidget(CardService.newTextButton()
      .setText('Turn on Apps Script API')
      .setOpenLink(CardService.newOpenLink()
        .setUrl('https://script.google.com/home/usersettings')
        .setOpenAs(CardService.OpenAs.FULL_SIZE)
        .setOnClose(CardService.OnClose.NOTHING)));

  // Configures card footer with action to copy the macro.
  var cardFooter = CardService.newFixedFooter()
    .setPrimaryButton(CardService.newTextButton()
      .setText('Share macro')
      .setOnClickAction(CardService.newAction()
        .setFunctionName('onClickFunction_')));

  // Begins building the card.
  let builder = CardService.newCardBuilder()
    .setHeader(cardHeader);

  // Adds error section if applicable.
  if (showErrors) {
    builder.addSection(sectionErrors)
  }

  // Adds final sections & footer.
  builder
    .addSection(sectionSource)
    .addSection(sectionTarget)
    .addSection(sectionHelp)
    .setFixedFooter(cardFooter);

  return builder.build();
}

/**
 * Action handler that validates user inputs and calls shareMacro_
 * function to copy Apps Script project to target spreadsheet.
 * 
 * @param {Object} e - Add-on event object.
 * 
 * @return {CardService.Card} Responds with either a success or error card.
 */
function onClickFunction_(e) {

  const sourceScriptId = e.formInput.sourceScriptId;
  const targetSpreadsheetUrl = e.formInput.targetSpreadsheetUrl;

  // Validates inputs for errors.
  const errors = [];

  // Pushes an error message if the Script ID parameter is missing.
  if (!sourceScriptId) {
    errors.push('Missing script ID');
  } else {

    // Gets the Apps Script project if the Script ID parameter is valid.
    const sourceProject = APPS_SCRIPT_API.get(sourceScriptId);
    if (!sourceProject) {
      // Pushes an error message if the Script ID parameter isn't valid.
      errors.push('Invalid script ID');
    }
  }

  // Pushes an error message if the spreadsheet URL is missing.
  if (!targetSpreadsheetUrl) {
    errors.push('Missing Spreadsheet URL');
  } else
    try {
      // Tests for valid spreadsheet URL to get the spreadsheet ID.
      const ssId = SpreadsheetApp.openByUrl(targetSpreadsheetUrl).getId();
    } catch (err) {
      // Pushes an error message if the spreadsheet URL parameter isn't valid.
      errors.push('Invalid spreadsheet URL');
    }

  if (errors && errors.length) {
    // Redisplays form if inputs are missing or invalid.
    return createSelectionCard(e, sourceScriptId, targetSpreadsheetUrl, errors);

  } else {
    // Calls shareMacro function to copy the project.
    shareMacro_(sourceScriptId, targetSpreadsheetUrl);

    // Creates a success card to display to users.
    return buildSuccessCard(e, targetSpreadsheetUrl);
  }
}

/**
 * Builds success card to inform user & let them open the spreadsheet.
 * 
 * @param {Object} e - Add-on event object.
 * @param {string} targetSpreadsheetUrl - URL of the target spreadsheet.
 * 
 * @return {CardService.Card} Returns success card.
 */function buildSuccessCard(e, targetSpreadsheetUrl) {

  // Configures card header.
  let cardHeader = CardService.newCardHeader()
    .setTitle('Share macros with other spreadsheets!')
    .setImageUrl(ADDON_LOGO)
    .setImageStyle(CardService.ImageStyle.SQUARE);

  // Configures card body section with success message and open button.
  let sectionBody1 = CardService.newCardSection()
    .addWidget(CardService.newTextParagraph()
      .setText('Sharing process is complete!'))
    .addWidget(CardService.newTextButton()
      .setText('Open spreadsheet')
      .setOpenLink(CardService.newOpenLink()
        .setUrl(targetSpreadsheetUrl)
        .setOpenAs(CardService.OpenAs.FULL_SIZE)
        .setOnClose(CardService.OnClose.RELOAD_ADD_ON)));
  let sectionBody2 = CardService.newCardSection()
    .addWidget(CardService.newTextParagraph()
      .setText('If you don\'t see the copied project in your target spreadsheet,' +
       ' make sure you turned on the Apps Script API in the Apps Script dashboard.'))
    .addWidget(CardService.newTextButton()
      .setText("Check API")
      .setOpenLink(CardService.newOpenLink()
        .setUrl('https://script.google.com/home/usersettings')
        .setOpenAs(CardService.OpenAs.FULL_SIZE)
        .setOnClose(CardService.OnClose.RELOAD_ADD_ON)));

  // Configures the card footer with action to start new process.
  let cardFooter = CardService.newFixedFooter()
    .setPrimaryButton(CardService.newTextButton()
      .setText('Share another')
      .setOnClickAction(CardService.newAction()
        .setFunctionName('onHomepage')));

  return builder = CardService.newCardBuilder()
    .setHeader(cardHeader)
    .addSection(sectionBody1)
    .addSection(sectionBody2)
    .setFixedFooter(cardFooter)
    .build();
 }

appsscript.json

solutions/add-on/share-macro/appsscript.json
{
  "timeZone": "America/Los_Angeles",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/spreadsheets",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/drive.readonly",
    "https://www.googleapis.com/auth/script.projects"
  ],
    "urlFetchWhitelist": [
    "https://script.googleapis.com/"
  ],
  "addOns": {
    "common": {
      "name": "Share Macro",
      "logoUrl": "https://www.gstatic.com/images/branding/product/2x/apps_script_48dp.png",
      "layoutProperties": {
        "primaryColor": "#188038",
        "secondaryColor": "#34a853"
      },
      "homepageTrigger": {
        "runFunction": "onHomepage"
      }
    },
    "sheets": {}
  }
}

অবদানকারী

এই নমুনা Google ডেভেলপার বিশেষজ্ঞদের সাহায্যে Google দ্বারা রক্ষণাবেক্ষণ করা হয়।

পরবর্তী পদক্ষেপ