উন্নত পত্রক পরিষেবা

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

তথ্যসূত্র

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

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

নমুনা কোড

নিচের নমুনা কোডটি API-এর ৪র্থ সংস্করণ ব্যবহার করে; এটিই Sheets API-এর একমাত্র সংস্করণ যা বর্তমানে Apps Script-এ উন্নত পরিষেবা হিসেবে উপলব্ধ।

একটি পরিসর থেকে মান পড়ুন

নিচের উদাহরণটি Sheets অ্যাডভান্সড সার্ভিসের সাহায্যে একটি শীটে একটি নির্দিষ্ট পরিসর থেকে ডেটা মান কীভাবে পড়তে হয় তা দেখায়। এটি Read a single range রেসিপি নমুনার সমতুল্য।

উন্নত/শিটস.জিএস
/**
 * Read a range (A1:D5) of data values. Logs the values.
 * @param {string} spreadsheetId The spreadsheet ID to read from.
 * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get
 */
function readRange(spreadsheetId = yourspreadsheetId) {
  try {
    const response = Sheets.Spreadsheets.Values.get(
      spreadsheetId,
      "Sheet1!A1:D5",
    );
    if (response.values) {
      console.log(response.values);
      return;
    }
    console.log("Failed to get range of values from spreadsheet");
  } catch (e) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", e.message);
  }
}

একাধিক পরিসরে মান লিখুন

নিচের উদাহরণটি দেখায় কিভাবে একটি অনুরোধের মাধ্যমে একটি শীটে বিভিন্ন, বিচ্ছিন্ন রেঞ্জে ডেটা লিখতে হয়। এটি Write to multiple ranges রেসিপি নমুনার সমতুল্য।

উন্নত/শিটস.জিএস
/**
 * Write to multiple, disjoint data ranges.
 * @param {string} spreadsheetId The spreadsheet ID to write to.
 * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate
 */
function writeToMultipleRanges(spreadsheetId = yourspreadsheetId) {
  // Specify some values to write to the sheet.
  const columnAValues = [["Item", "Wheel", "Door", "Engine"]];
  const rowValues = [
    ["Cost", "Stocked", "Ship Date"],
    ["$20.50", "4", "3/1/2016"],
  ];

  const request = {
    valueInputOption: "USER_ENTERED",
    data: [
      {
        range: "Sheet1!A1:A4",
        majorDimension: "COLUMNS",
        values: columnAValues,
      },
      {
        range: "Sheet1!B1:D2",
        majorDimension: "ROWS",
        values: rowValues,
      },
    ],
  };
  try {
    const response = Sheets.Spreadsheets.Values.batchUpdate(
      request,
      spreadsheetId,
    );
    if (response) {
      console.log(response);
      return;
    }
    console.log("response null");
  } catch (e) {
    // TODO (developer) - Handle  exception
    console.log("Failed with error %s", e.message);
  }
}

একটি নতুন পত্রক যোগ করুন

নিচের উদাহরণটি নির্দিষ্ট আকার এবং ট্যাব রঙের সাথে একটি নতুন শীট কীভাবে তৈরি করতে হয় তা দেখায়। এটি একটি শীট রেসিপি নমুনা যোগ করুন এর সমতুল্য।

উন্নত/শিটস.জিএস
/**
 * Add a new sheet with some properties.
 * @param {string} spreadsheetId The spreadsheet ID.
 * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate
 */
function addSheet(spreadsheetId = yourspreadsheetId) {
  const requests = [
    {
      addSheet: {
        properties: {
          title: "Deposits",
          gridProperties: {
            rowCount: 20,
            columnCount: 12,
          },
          tabColor: {
            red: 1.0,
            green: 0.3,
            blue: 0.4,
          },
        },
      },
    },
  ];
  try {
    const response = Sheets.Spreadsheets.batchUpdate(
      { requests: requests },
      spreadsheetId,
    );
    console.log(
      `Created sheet with ID: ${response.replies[0].addSheet.properties.sheetId}`,
    );
  } catch (e) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", e.message);
  }
}

একটি পিভট টেবিল তৈরি করুন

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

উন্নত/শিটস.জিএস
/**
 * Add a pivot table.
 * @param {string} spreadsheetId The spreadsheet ID to add the pivot table to.
 * @param {string} pivotSourceDataSheetId The sheet ID to get the data from.
 * @param {string} destinationSheetId The sheet ID to add the pivot table to.
 * @see https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate
 */
function addPivotTable(
  spreadsheetId = yourspreadsheetId,
  pivotSourceDataSheetId = yourpivotSourceDataSheetId,
  destinationSheetId = yourdestinationSheetId,
) {
  const requests = [
    {
      updateCells: {
        rows: {
          values: [
            {
              pivotTable: {
                source: {
                  sheetId: pivotSourceDataSheetId,
                  startRowIndex: 0,
                  startColumnIndex: 0,
                  endRowIndex: 20,
                  endColumnIndex: 7,
                },
                rows: [
                  {
                    sourceColumnOffset: 0,
                    showTotals: true,
                    sortOrder: "ASCENDING",
                    valueBucket: {
                      buckets: [
                        {
                          stringValue: "West",
                        },
                      ],
                    },
                  },
                  {
                    sourceColumnOffset: 1,
                    showTotals: true,
                    sortOrder: "DESCENDING",
                    valueBucket: {},
                  },
                ],
                columns: [
                  {
                    sourceColumnOffset: 4,
                    sortOrder: "ASCENDING",
                    showTotals: true,
                    valueBucket: {},
                  },
                ],
                values: [
                  {
                    summarizeFunction: "SUM",
                    sourceColumnOffset: 3,
                  },
                ],
                valueLayout: "HORIZONTAL",
              },
            },
          ],
        },
        start: {
          sheetId: destinationSheetId,
          rowIndex: 49,
          columnIndex: 0,
        },
        fields: "pivotTable",
      },
    },
  ];
  try {
    const response = Sheets.Spreadsheets.batchUpdate(
      { requests: requests },
      spreadsheetId,
    );
    // The Pivot table will appear anchored to cell A50 of the destination sheet.
  } catch (e) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", e.message);
  }
}