লাইব্রেরি কুইকস্টার্ট
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
একটি অ্যাপস স্ক্রিপ্ট লাইব্রেরি তৈরি করুন যা আপনি স্প্রেডশীট ডেটাতে ডুপ্লিকেট সারিগুলি সরাতে ব্যবহার করতে পারেন৷
উদ্দেশ্য
- স্ক্রিপ্ট সেট আপ করুন।
- স্ক্রিপ্ট চালান।
পূর্বশর্ত
এই নমুনা ব্যবহার করতে, আপনার নিম্নলিখিত পূর্বশর্ত প্রয়োজন:
- একটি Google অ্যাকাউন্ট (Google Workspace অ্যাকাউন্টের জন্য অ্যাডমিনিস্ট্রেটরের অনুমোদনের প্রয়োজন হতে পারে)।
- ইন্টারনেট অ্যাক্সেস সহ একটি ওয়েব ব্রাউজার।
স্ক্রিপ্ট সেট আপ করুন
লাইব্রেরি তৈরি করতে, নিম্নলিখিত পদক্ষেপগুলি নিন:
- আপনার Google অ্যাকাউন্টে সাইন ইন করুন।
- স্ক্রিপ্ট সম্পাদক খুলতে, script.google.com এ যান।
- উপরের বাম দিকে, নতুন প্রকল্পে ক্লিক করুন।
স্ক্রিপ্ট এডিটর থেকে যেকোনো কোড মুছুন এবং নিচের কোডে পেস্ট করুন।
Save এ ক্লিক করুন
.
উপরের বাম দিকে, শিরোনামহীন প্রকল্পে ক্লিক করুন।
আপনার স্ক্রিপ্টের নাম দিন ডুপ্লিকেট সারিগুলি সরান এবং পুনঃনামকরণ ক্লিক করুন।
Deploy > New deployment এ ক্লিক করুন।
নির্বাচন প্রকারের পাশে স্থাপনার প্রকারগুলি সক্ষম করুন ক্লিক করুন
> লাইব্রেরি ।
লাইব্রেরির একটি বিবরণ লিখুন, যেমন ডুপ্লিকেট সারি সরান । লাইব্রেরিতে অ্যাক্সেস আছে এমন যে কেউ এই বিবরণ দেখতে পারেন।
Deploy এ ক্লিক করুন।
বাম দিকে, প্রকল্প সেটিংস ক্লিক করুন
.
আইডির অধীনে, পরবর্তী ধাপে ব্যবহারের জন্য স্ক্রিপ্ট আইডি কপি করুন।
স্ক্রিপ্ট চালান
একটি লাইব্রেরি ব্যবহার করতে, আপনার অ্যাপস স্ক্রিপ্ট প্রকল্পের জন্য কমপক্ষে দেখার অনুমতি থাকতে হবে। যেহেতু আপনি লাইব্রেরি তৈরি করেছেন, আপনার কাছে এটি ব্যবহার করার প্রয়োজনীয় অনুমতি রয়েছে৷ আপনি যদি অন্যদের লাইব্রেরি ব্যবহার করতে দিতে চান, তাহলে তাদের Apps Script প্রকল্পের জন্য দেখার অনুমতি দিন।
লাইব্রেরি ব্যবহার করতে, নিম্নলিখিত পদক্ষেপগুলি নিন:
- একটি Google পত্রক স্প্রেডশীট খুলুন যাতে ডুপ্লিকেট সারি সহ ডেটা রয়েছে৷ একটি নমুনা স্প্রেডশীট ব্যবহার করতে, নমুনা ডুপ্লিকেট সারি স্প্রেডশীটের একটি অনুলিপি তৈরি করুন ৷
- এক্সটেনশন > অ্যাপস স্ক্রিপ্টে ক্লিক করুন।
- লাইব্রেরির পাশে, একটি লাইব্রেরি add করুন ক্লিক করুন।
- স্ক্রিপ্ট আইডি বিভাগে, লাইব্রেরি অ্যাপস স্ক্রিপ্ট প্রকল্প থেকে স্ক্রিপ্ট আইডি পেস্ট করুন যা আপনি পূর্ববর্তী বিভাগে অনুলিপি করেছেন।
- দেখুন ক্লিক করুন.
- সংস্করণ বিভাগে, 1 নির্বাচন করুন।
- যোগ করুন ক্লিক করুন।
স্ক্রিপ্ট এডিটর থেকে যেকোনো কোড মুছুন এবং নিচের কোডে পেস্ট করুন।
function runLibrary() {
Removeduplicaterows.removeDuplicates();
}
ফাংশন ড্রপডাউনে, runLibrary নির্বাচন করুন।
রান এ ক্লিক করুন।
ডুপ্লিকেট সারি ছাড়া আপডেট করা ডেটা দেখতে স্প্রেডশীটে ফিরে যান।
কোড পর্যালোচনা করুন
এই সমাধানের জন্য অ্যাপস স্ক্রিপ্ট কোড পর্যালোচনা করতে, নীচের উৎস কোড দেখুন ক্লিক করুন:
সোর্স কোড দেখুন
প্রথমত, স্ক্রিপ্টটি সমস্ত ডেটা পুনরুদ্ধার করতে স্প্রেডশীটে একক কল করে। আপনি সারি অনুসারে শীট সারি পড়তে বেছে নিতে পারেন, তবে জাভাস্ক্রিপ্ট অপারেশনগুলি স্প্রেডশীটের মতো অন্যান্য পরিষেবাগুলির সাথে কথা বলার চেয়ে যথেষ্ট দ্রুত। আপনি যত কম কল করবেন, তত দ্রুত যাবে। এটি গুরুত্বপূর্ণ কারণ প্রতিটি স্ক্রিপ্ট এক্সিকিউশনের সর্বোচ্চ রান টাইম 6 মিনিট।
ভেরিয়েবল data
হল একটি জাভাস্ক্রিপ্ট 2-ডাইমেনশনাল অ্যারে যা শীটের সমস্ত মান ধারণ করে। newData
হল একটি খালি অ্যারে যেখানে স্ক্রিপ্ট সমস্ত নন-ডুপ্লিকেট সারি রাখে।
লুপের for
প্রথমটি data
2-ডাইমেনশনাল অ্যারের প্রতিটি সারির উপর পুনরাবৃত্তি করে। প্রতিটি সারির জন্য, দ্বিতীয় লুপ পরীক্ষা করে যে newData
অ্যারেতে মিলিত ডেটা সহ অন্য সারি ইতিমধ্যেই বিদ্যমান আছে কিনা। যদি এটি একটি সদৃশ না হয়, সারিটি newData
অ্যারেতে ঠেলে দেওয়া হয়।
অবশেষে, স্ক্রিপ্টটি শীটের বিদ্যমান বিষয়বস্তু মুছে দেয় এবং newData
অ্যারের বিষয়বস্তু সন্নিবেশ করায়।
পরিবর্তন
আপনি আপনার প্রয়োজন অনুসারে লাইব্রেরি সম্পাদনা করতে পারেন। নীচে একটি ঐচ্ছিক পরিবর্তন আছে.
কিছু কলামে মিলে যাওয়া ডেটা সহ সারিগুলি সরান৷
সম্পূর্ণভাবে মেলে এমন সারিগুলি সরানোর পরিবর্তে, আপনি কেবলমাত্র এক বা দুটি কলামে মিলে যাওয়া ডেটা সহ সারিগুলি সরাতে চাইতে পারেন৷ এটি করতে, আপনি শর্তসাপেক্ষ বিবৃতি পরিবর্তন করতে পারেন।
নমুনা কোডে, নিম্নলিখিত লাইন আপডেট করুন:
if(row.join() == newData[j].join()){
duplicate = true;
}
নিম্নলিখিত কোড দিয়ে লাইন প্রতিস্থাপন করুন:
if(row[0] == newData[j][0] && row[1] == newData[j][1]){
duplicate = true;
}
উপরের শর্তসাপেক্ষ বিবৃতিটি প্রতিবার শীটের প্রথম এবং দ্বিতীয় কলামে দুটি সারিতে একই ডেটা থাকলে ডুপ্লিকেট খুঁজে পায়।
অবদানকারী
এই নমুনাটি তৈরি করেছেন রোমেন ভিয়ালার্ড, একজন গুগল ডেভেলপার বিশেষজ্ঞ। টুইটারে রোমেনকে অনুসরণ করুন @romain_vialard ।
এই নমুনা Google ডেভেলপার বিশেষজ্ঞদের সাহায্যে Google দ্বারা রক্ষণাবেক্ষণ করা হয়।
পরবর্তী পদক্ষেপ
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-08-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eThis guide provides step-by-step instructions to create an Apps Script library that removes duplicate rows from Google Sheets data.\u003c/p\u003e\n"],["\u003cp\u003eThe library uses a JavaScript function to identify and remove duplicate rows by comparing all column values within each row.\u003c/p\u003e\n"],["\u003cp\u003eUsers need a Google Account and a web browser to implement this solution, which involves setting up, deploying, and running the script within a spreadsheet.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code can be modified to remove rows based on matching data in specific columns, enhancing the library's functionality.\u003c/p\u003e\n"]]],[],null,["# Library quickstart\n\nBuild an [Apps Script library](/apps-script/guides/libraries) that you can use to remove duplicate rows in spreadsheet data.\n\nObjectives\n----------\n\n- Set up the script.\n- Run the script.\n\nPrerequisites\n-------------\n\nTo use this sample, you need the following prerequisites:\n\n- A Google Account (Google Workspace accounts might require administrator approval).\n- A web browser with access to the internet.\n\nSet up the script\n-----------------\n\nTo build the library, take the following steps:\n\n1. Sign in to your Google Account.\n2. To open the script editor, go to [script.google.com](https://script.google.com/home).\n3. At the top left, click **New project**.\n4. Delete any code in the script editor and paste in the code below.\n\n sheets/removingDuplicates/removingDuplicates.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/removingDuplicates/removingDuplicates.gs) \n\n ```javascript\n /**\n * Removes duplicate rows from the current sheet.\n */\n function removeDuplicates() {\n const sheet = SpreadsheetApp.getActiveSheet();\n const data = sheet.getDataRange().getValues();\n const uniqueData = {};\n for (let row of data) {\n const key = row.join();\n uniqueData[key] = uniqueData[key] || row;\n }\n sheet.clearContents();\n const newData = Object.values(uniqueData);\n sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);\n }\n ```\n5. Click Save .\n\n6. At the top left, click **Untitled project**.\n\n7. Name your script **Remove duplicate rows** and click **Rename**.\n\n8. Click **Deploy** \\\u003e **New deployment**.\n\n9. Next to **Select type** click Enable deployment types\n\n \\\u003e **Library**.\n\n10. Enter a description of the library, such as **Remove duplicate rows**. Anyone\n with access to the library can view this description.\n\n11. Click **Deploy**.\n\n12. At the left, click **Project settings** .\n\n13. Under **IDs**, copy the script ID for use in a later step.\n\nRun the script\n--------------\n\nTo use a library, you must have at least view permissions for its\nApps Script project. Since you created the library, you have the\nrequired permissions\nto use it. If you want to let others use the library, give them view permission\nfor the Apps Script project.\n\nTo use the library, take the following steps:\n\n1. Open a Google Sheets spreadsheet that has data with duplicate rows. To use a sample spreadsheet, [make a copy of the **Sample duplicate rows** spreadsheet](https://docs.google.com/spreadsheets/d/1_Tcb0kokQIYCEz_nWnxUHZp8nwTysjjxucMmVZ0DeSg/copy?usp=sharing).\n2. Click **Extensions** \\\u003e **Apps Script**.\n3. Next to **Libraries** , click Add a library add.\n4. In the **Script ID** section, paste the script ID from the library Apps Script project you copied in the previous section.\n5. Click **Look up**.\n6. In the **Version** section, select **1**.\n7. Click **Add**.\n8. Delete any code in the script editor and paste in the code below.\n\n function runLibrary() {\n Removeduplicaterows.removeDuplicates();\n }\n\n9. In the function dropdown, select **runLibrary**.\n\n10. Click **Run**.\n\n11. Return to the spreadsheet to view the updated data without duplicate rows.\n\nReview the code\n---------------\n\nTo review the Apps Script code for this solution, click **View source code**\nbelow: \n\n#### View the source code\n\n\nFirst, the script makes a single call to the spreadsheet to retrieve all the\ndata. You can choose to read the sheet row by row, but JavaScript operations are\nconsiderably faster than talking to other services like Spreadsheet. The fewer\ncalls you make, the faster it goes. This is important because each script\nexecution has a maximum run time of 6 minutes. \nsheets/removingDuplicates/removingDuplicates.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/removingDuplicates/removingDuplicates.gs) \n\n```javascript\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst data = sheet.getDataRange().getValues();\n```\n\n\nThe variable `data` is a JavaScript 2-dimensional array that contains\nall the values in the sheet. `newData` is an empty array where the\nscript puts all the non-duplicate rows. \nsheets/removingDuplicates/removingDuplicates.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/removingDuplicates/removingDuplicates.gs) \n\n```javascript\nconst newData = Object.values(uniqueData);\n```\n\n\nThe first `for` loop iterates over each row in the `data`\n2-dimensional array. For each row, the second loop tests if another row with\nmatching data already exists in the `newData` array. If it's not a\nduplicate, the row is pushed into the `newData` array. \nsheets/removingDuplicates/removingDuplicates.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/removingDuplicates/removingDuplicates.gs) \n\n```javascript\nuniqueData[key] = uniqueData[key] || row;\n```\n\n\nFinally, the script deletes the existing content of the sheet and inserts\nthe content of the `newData` array. \nsheets/removingDuplicates/removingDuplicates.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/removingDuplicates/removingDuplicates.gs) \n\n```javascript\nsheet.clearContents();\nconst newData = Object.values(uniqueData);\nsheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);\n```\n\nModifications\n-------------\n\nYou can edit the library as much as you'd like to fit your needs. Below is an\noptional modification. \n\n#### Remove rows with matching data in some columns\n\n\nInstead of removing rows that match entirely, you might want to remove rows with\nmatching data in just one or two of the columns. To do that, you can change the\nconditional statement.\n\n\nIn the sample code, update the following line: \n\n```transact-sql\n if(row.join() == newData[j].join()){\n duplicate = true;\n }\n```\n\n\nReplace the line with the following code: \n\n```transact-sql\n if(row[0] == newData[j][0] && row[1] == newData[j][1]){\n duplicate = true;\n }\n```\n\n\nThe above conditional statement finds duplicates each time two rows have the\nsame data in the first and second columns of the sheet.\n\nContributors\n------------\n\nThis sample was created by Romain Vialard, a Google Developer Expert. Follow\nRomain on Twitter [@romain_vialard](https://twitter.com/romain_vialard).\n\nThis sample is maintained by Google with the help of Google Developer Experts.\n\nNext steps\n----------\n\n- [Libraries](/apps-script/guides/libraries)\n- [Create and manage deployments](/apps-script/concepts/deployments)"]]