একাধিক পত্রক থেকে ডেটা সংক্ষিপ্ত করুন

কোডিং স্তর : শিক্ষানবিস
সময়কাল : 5 মিনিট
প্রকল্পের ধরন : কাস্টম ফাংশন

উদ্দেশ্য

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

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

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

getSheetsData ফাংশন আউটপুটের স্ক্রিনশট

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

কাস্টম ফাংশন, getSheetsData() নামে পরিচিত, একটি শীটের স্থিতি কলামের উপর ভিত্তি করে স্প্রেডশীটের প্রতিটি শীট থেকে ডেটা সংক্ষিপ্ত করে। স্ক্রিপ্টটি শীটগুলিকে উপেক্ষা করে যেগুলিকে একত্রিত করা উচিত নয়, যেমন ReadMe এবং সারাংশ শীট৷

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

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

  • স্প্রেডশীট পরিষেবা - শীটগুলিকে সংক্ষিপ্ত করা প্রয়োজন এবং একটি নির্দিষ্ট স্ট্রিংয়ের সাথে মেলে এমন আইটেমের সংখ্যা গণনা করে৷ তারপর, স্প্রেডশীটে যেখানে কাস্টম ফাংশন কল করা হয়েছিল তার সাথে সম্পর্কিত একটি পরিসরে স্ক্রিপ্ট গণনা করা তথ্য যোগ করে।

পূর্বশর্ত

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

  • একটি Google অ্যাকাউন্ট (Google Workspace অ্যাকাউন্টের জন্য অ্যাডমিনিস্ট্রেটরের অনুমোদনের প্রয়োজন হতে পারে)।
  • ইন্টারনেট অ্যাক্সেস সহ একটি ওয়েব ব্রাউজার।

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

সারমাইজ স্প্রেডশীট ডেটা কাস্টম ফাংশন স্প্রেডশীটের একটি অনুলিপি করতে নীচের বোতামে ক্লিক করুন। এই সমাধানের জন্য অ্যাপস স্ক্রিপ্ট প্রকল্পটি স্প্রেডশীটের সাথে সংযুক্ত রয়েছে৷
একটি কপি করো

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

  1. আপনার কপি করা স্প্রেডশীটে, সারাংশ শীটে যান।
  2. সেল A4 ক্লিক করুন। getSheetsData() ফাংশন এই ঘরে রয়েছে।
  3. মালিকের শীটগুলির একটিতে যান এবং শীটে ডেটা আপডেট করুন বা যুক্ত করুন৷ আপনি চেষ্টা করতে পারেন এমন কিছু কর্মের মধ্যে নিম্নলিখিতগুলি অন্তর্ভুক্ত রয়েছে:
    • নমুনা টিকিটের তথ্য সহ একটি নতুন সারি যোগ করুন।
    • স্ট্যাটাস কলামে, বিদ্যমান টিকিটের স্থিতি পরিবর্তন করুন।
    • স্থিতি কলামের অবস্থান পরিবর্তন করুন। উদাহরণস্বরূপ, Owner1 শীটে, স্থিতি কলামটি কলাম C থেকে কলাম D এ সরান।
  4. সারাংশ শীটে যান এবং A4 সেল থেকে তৈরি করা getSheetsData() আপডেট করা সারণীটি পর্যালোচনা করুন। কাস্টম ফাংশনের ক্যাশে ফলাফল রিফ্রেশ করতে আপনাকে 10 সারিতে চেকবক্স চেক করতে হতে পারে। কর্মক্ষমতা অপ্টিমাইজ করতে Google কাস্টম ফাংশন ক্যাশ করে।
    • আপনি সারি যোগ বা আপডেট করলে, স্ক্রিপ্টটি টিকিট এবং স্থিতির সংখ্যা আপডেট করে।
    • আপনি যদি স্ট্যাটাস কলামের অবস্থান সরান, স্ক্রিপ্টটি এখনও নতুন কলাম সূচীর সাথে উদ্দেশ্য অনুযায়ী কাজ করে।

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

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

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

Code.gs

solutions/custom-functions/summarize-sheets-data/Code.js
// To learn how to use this script, refer to the documentation:
// https://developers.google.com/apps-script/samples/custom-functions/summarize-sheets-data

/*
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.
*/

/**
 * Gets summary data from other sheets. The sheets you want to summarize must have columns with headers that match the names of the columns this function summarizes data from.
 * 
 * @return {string} Summary data from other sheets.
 * @customfunction
 */

// The following sheets are ignored. Add additional constants for other sheets that should be ignored.
const READ_ME_SHEET_NAME = "ReadMe";
const PM_SHEET_NAME = "Summary";

/**
 * Reads data ranges for each sheet. Filters and counts based on 'Status' columns. To improve performance, the script uses arrays 
 * until all summary data is gathered. Then the script writes the summary array starting at the cell of the custom function.
 */
function getSheetsData() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let sheets = ss.getSheets();
  let outputArr = [];

  // For each sheet, summarizes the data and pushes to a temporary array.
  for (let s in sheets) {
    // Gets sheet name.
    let sheetNm = sheets[s].getName();
    // Skips ReadMe and Summary sheets.
    if (sheetNm === READ_ME_SHEET_NAME || sheetNm === PM_SHEET_NAME) { continue; }
    // Gets sheets data.
    let values = sheets[s].getDataRange().getValues();
    // Gets the first row of the sheet which is the header row.
    let headerRowValues = values[0];
    // Finds the columns with the heading names 'Owner Name' and 'Status' and gets the index value of each.
    // Using 'indexOf()' to get the position of each column prevents the script from breaking if the columns change positions in a sheet.
    let columnOwner = headerRowValues.indexOf("Owner Name");
    let columnStatus = headerRowValues.indexOf("Status");
    // Removes header row.
    values.splice(0,1);
    // Gets the 'Owner Name' column value by retrieving the first data row in the array.
    let owner = values[0][columnOwner];
    // Counts the total number of tasks.
    let taskCnt = values.length;
    // Counts the number of tasks that have the 'Complete' status.
    // If the options you want to count in your spreadsheet differ, update the strings below to match the text of each option.
    // To add more options, copy the line below and update the string to the new text.
    let completeCnt = filterByPosition(values,'Complete', columnStatus).length;
    // Counts the number of tasks that have the 'In-Progress' status.
    let inProgressCnt = filterByPosition(values,'In-Progress', columnStatus).length;
    // Counts the number of tasks that have the 'Scheduled' status.
    let scheduledCnt = filterByPosition(values,'Scheduled', columnStatus).length;
    // Counts the number of tasks that have the 'Overdue' status.
    let overdueCnt = filterByPosition(values,'Overdue', columnStatus).length;
    // Builds the output array.
    outputArr.push([owner,taskCnt,completeCnt,inProgressCnt,scheduledCnt,overdueCnt,sheetNm]);
  }
  // Writes the output array.
  return outputArr;
}

/**
 * Below is a helper function that filters a 2-dimenstional array.
 */
function filterByPosition(array, find, position) {
  return array.filter(innerArray => innerArray[position] === find);
}

পরিবর্তন

আপনি আপনার প্রয়োজন অনুসারে কাস্টম ফাংশন সম্পাদনা করতে পারেন। কাস্টম ফাংশন ফলাফল ম্যানুয়ালি রিফ্রেশ করার জন্য নীচে একটি ঐচ্ছিক সংযোজন।

ক্যাশে করা ফলাফল রিফ্রেশ করুন

অন্তর্নির্মিত ফাংশনগুলির বিপরীতে, Google পারফরম্যান্স অপ্টিমাইজ করতে কাস্টম ফাংশনগুলি ক্যাশে করে। এর মানে হল যে আপনি যদি আপনার কাস্টম ফাংশনের মধ্যে কিছু পরিবর্তন করেন, যেমন একটি মান যা গণনা করা হচ্ছে, এটি অবিলম্বে একটি আপডেট জোর করে নাও পারে। ম্যানুয়ালি ফাংশন ফলাফল রিফ্রেশ করতে, নিম্নলিখিত পদক্ষেপগুলি নিন:

  1. সন্নিবেশ > চেকবক্সে ক্লিক করে একটি খালি ঘরে একটি চেকবক্স যোগ করুন।
  2. কাস্টম ফাংশনের প্যারামিটার হিসাবে চেকবক্স আছে এমন সেল যোগ করুন, উদাহরণস্বরূপ, getSheetsData(B11)
  3. কাস্টম ফাংশন ফলাফল রিফ্রেশ করতে চেকবক্স চেক বা আনচেক করুন.

অবদানকারী

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

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