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

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

রেফারেন্স

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

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

কোডের উদাহরণ

নিচের নমুনা কোডটি API এর 4 সংস্করণ ব্যবহার করে; এটি শীট API-এর একমাত্র সংস্করণ যা বর্তমানে Apps স্ক্রিপ্টে একটি উন্নত পরিষেবা হিসাবে উপলব্ধ৷

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

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

advanced/sheets.gs
/**
 * 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);
  }
}

একাধিক রেঞ্জে মান লিখুন

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

advanced/sheets.gs
/**
 * 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);
  }
}

একটি নতুন শীট যোগ করুন

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

advanced/sheets.gs
/**
 * 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);
  }
}

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

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

advanced/sheets.gs
/**
 * 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);
  }
}