পড়ুন & সেল মান লিখুন

স্প্রেডশিটে একাধিক শিট থাকতে পারে, প্রতিটি শিটে যেকোনো সংখ্যক সারি বা কলাম থাকতে পারে। একটি ঘর হল একটি নির্দিষ্ট সারি এবং কলামের ছেদস্থলে অবস্থিত একটি অবস্থান এবং এতে একটি ডেটা মান থাকতে পারে। Google Sheets API মানগুলি পড়া এবং লেখা সক্ষম করার জন্য spreadsheets.values ​​রিসোর্স প্রদান করে।

এই পৃষ্ঠাটি spreadsheets.values ​​রিসোর্স ব্যবহারের মূল বিষয়গুলি বর্ণনা করে। যদি আপনার কোনও শীটে সারি সন্নিবেশ করানো বা ফর্ম্যাটিং এবং অন্যান্য বৈশিষ্ট্য আপডেট করার প্রয়োজন হয়, তাহলে আপনাকে Update spreadsheets এ বর্ণিত spreadsheets.batchUpdate পদ্ধতিটি ব্যবহার করতে হবে।

পদ্ধতি

spreadsheets.values রিসোর্সটি একটি নির্দিষ্ট কাজের জন্য মান পড়ার এবং লেখার জন্য নিম্নলিখিত পদ্ধতিগুলি প্রদান করে:

রেঞ্জ অ্যাক্সেস পড়া লেখা
একক পরিসর spreadsheets.values.get spreadsheets.values.update
একাধিক ব্যাপ্তি spreadsheets.values.batchGet spreadsheets.values.batchUpdate
সংযোজন spreadsheets.values.append

সাধারণভাবে, batchGet এবং batchUpdate পদ্ধতির সাথে (যথাক্রমে) একাধিক পঠন বা আপডেট একত্রিত করা একটি ভাল ধারণা, কারণ এটি দক্ষতা উন্নত করে।

আপনি বেসিক রিডিং এবং বেসিক লেখার নমুনা পৃষ্ঠাগুলিতে এই প্রতিটি পদ্ধতির উদাহরণ খুঁজে পেতে পারেন। সমস্ত নমুনা দেখতে, নমুনা ওভারভিউ পৃষ্ঠাটি দেখুন।

পড়ুন

একটি শীট থেকে ডেটা মান পড়ার জন্য, আপনার স্প্রেডশিট আইডি এবং পরিসরের জন্য A1 নোটেশন প্রয়োজন। শীট আইডি ( A1:B2 ) ছাড়া রেঞ্জ নির্দিষ্ট করার অর্থ হল অনুরোধটি স্প্রেডশিটের প্রথম শীটে কার্যকর হবে। স্প্রেডশিট আইডি এবং A1 নোটেশন সম্পর্কে আরও তথ্যের জন্য, Google Sheets API ওভারভিউ দেখুন।

বেশ কিছু ঐচ্ছিক কোয়েরি প্যারামিটার আউটপুটের ফর্ম্যাট নিয়ন্ত্রণ করে:

বিন্যাস পরামিতি ডিফল্ট মান
majorDimension সারি
valueRenderOption ফর্ম্যাটেড_ভ্যালু
dateTimeRenderOption SERIAL_NUMBER টি

মনে রাখবেন যে আপনার শুধুমাত্র dateTimeRenderOption ব্যবহার করা উচিত যদি valueRenderOption FORMATTED_VALUE না হয়।

কত ডেটা ফেরত দেওয়া হবে তার কোনও স্পষ্ট সীমা নেই। ত্রুটিগুলি কোনও ডেটা ফেরত দেয় না। খালি পিছনের সারি এবং কলামগুলি বাদ দেওয়া হয়েছে।

নিচে singular এবং batch get পদ্ধতি বর্ণনা করা হল। মৌলিক পঠন ক্রিয়াকলাপের নমুনার জন্য, মৌলিক পঠন দেখুন।

একটি একক পরিসর পড়ুন

একটি স্প্রেডশিট থেকে একটি একক পরিসরের মান পড়তে, একটি spreadsheets.values.get অনুরোধ ব্যবহার করুন:

অ্যাপস স্ক্রিপ্ট

শিটস/এপিআই/স্প্রেডশিট_স্নিপেটস.জিএস
/**
 * Gets the values of the cells in the specified range
 * @param {string} spreadsheetId id of the spreadsheet
 * @param {string} range specifying the start and end cells of the range
 * @returns {*} Values in the range
 */
Snippets.prototype.getValues = (spreadsheetId, range) => {
  // This code uses the Sheets Advanced Service, but for most use cases
  // the built-in method SpreadsheetApp.getActiveSpreadsheet()
  //     .getRange(range).getValues(values) is more appropriate.
  try {
    const result = Sheets.Spreadsheets.Values.get(spreadsheetId, range);
    const numRows = result.values ? result.values.length : 0;
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", err.message);
  }
};

জাভা

শীট/স্নিপেট/src/main/java/GetValues.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.ValueRange;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

/* Class to demonstrate the use of Spreadsheet Get Values API */
public class GetValues {
  /**
   * Returns a range of values from a spreadsheet.
   *
   * @param spreadsheetId - Id of the spreadsheet.
   * @param range         - Range of cells of the spreadsheet.
   * @return Values in the range
   * @throws IOException - if credentials file not found.
   */
  public static ValueRange getValues(String spreadsheetId, String range) throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the sheets API client
    Sheets service = new Sheets.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Sheets samples")
        .build();

    ValueRange result = null;
    try {
      // Gets the values of the cells in the specified range.
      result = service.spreadsheets().values().get(spreadsheetId, range).execute();
      int numRows = result.getValues() != null ? result.getValues().size() : 0;
      System.out.printf("%d rows retrieved.", numRows);
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 404) {
        System.out.printf("Spreadsheet not found with id '%s'.\n", spreadsheetId);
      } else {
        throw e;
      }
    }
    return result;
  }
}

জাভাস্ক্রিপ্ট

শিট/স্নিপেট/শিট_গেট_ভ্যালু.জেএস
function getValues(spreadsheetId, range, callback) {
  try {
    gapi.client.sheets.spreadsheets.values.get({
      spreadsheetId: spreadsheetId,
      range: range,
    }).then((response) => {
      const result = response.result;
      const numRows = result.values ? result.values.length : 0;
      console.log(`${numRows} rows retrieved.`);
      if (callback) callback(response);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

নোড.জেএস

শিট/স্নিপেট/শিট_গেট_ভ্যালু.জেএস
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Gets cell values from a spreadsheet.
 * @param {string} spreadsheetId The ID of the spreadsheet.
 * @param {string} range The range of cells to retrieve.
 * @return {Promise<object>} The response from the get request.
 */
async function getValues(spreadsheetId, range) {
  // Authenticate with Google and get an authorized client.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/spreadsheets',
  });

  // Create a new Sheets API client.
  const service = google.sheets({version: 'v4', auth});
  // Get the values from the specified range.
  const result = await service.spreadsheets.values.get({
    spreadsheetId,
    range,
  });
  const numRows = result.data.values ? result.data.values.length : 0;
  console.log(`${numRows} rows retrieved.`);
  return result;
}

পিএইচপি

শীট/স্নিপেট/src/স্প্রেডশিটগেটভ্যালু.php
<?php
use Google\Client;
use Google\Service\Drive;
use Google\Service\Sheets\BatchUpdateSpreadsheetRequest;
/**
 * get values of a particular spreadsheet(by Id and range).
 */
function getValues($spreadsheetId, $range)
    {   
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
        $client = new Google\Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Google\Service\Drive::DRIVE);
        $service = new Google_Service_Sheets($client);
        $result = $service->spreadsheets_values->get($spreadsheetId, $range);
        try{
        $numRows = $result->getValues() != null ? count($result->getValues()) : 0;
        printf("%d rows retrieved.", $numRows);
        return $result;
    }
        catch(Exception $e) {
            // TODO(developer) - handle error appropriately
            echo 'Message: ' .$e->getMessage();
        }
    }

পাইথন

শীট/স্নিপেট/শীট_গেট_ভ্যালু.পি
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def get_values(spreadsheet_id, range_name):
  """
  Creates the batch_update the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    service = build("sheets", "v4", credentials=creds)

    result = (
        service.spreadsheets()
        .values()
        .get(spreadsheetId=spreadsheet_id, range=range_name)
        .execute()
    )
    rows = result.get("values", [])
    print(f"{len(rows)} rows retrieved")
    return result
  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Pass: spreadsheet_id, and range_name
  get_values("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k", "A1:C2")

রুবি

শিট/স্নিপেট/লিব/স্প্রেডশিট_স্নিপেটস.আরবি
result = service.get_spreadsheet_values(spreadsheet_id, range_name)
num_rows = result.values ? result.values.length : 0
puts "#{num_rows} rows received."

এই অনুরোধের প্রতিক্রিয়া একটি ValueRange অবজেক্ট হিসেবে ফেরত পাঠানো হয়।

একাধিক রেঞ্জ পড়ুন

একটি স্প্রেডশিট থেকে একাধিক, বিচ্ছিন্ন পরিসরের মান পড়তে, একটি spreadsheets.values.batchGet অনুরোধ ব্যবহার করুন যা আপনাকে পুনরুদ্ধার করার জন্য বেশ কয়েকটি পরিসর নির্দিষ্ট করতে দেয়:

অ্যাপস স্ক্রিপ্ট

শিটস/এপিআই/স্প্রেডশিট_স্নিপেটস.জিএস
/**
 * Get the values in the specified ranges
 * @param {string} spreadsheetId spreadsheet's ID
 * @param {list<string>} _ranges The span of ranges
 * @returns {*} spreadsheet information and values
 */
Snippets.prototype.batchGetValues = (spreadsheetId, _ranges) => {
  // This code uses the Sheets Advanced Service, but for most use cases
  // the built-in method SpreadsheetApp.getActiveSpreadsheet()
  //     .getRange(range).getValues(values) is more appropriate.
  let ranges = [
    //Range names ...
  ];
  try {
    const result = Sheets.Spreadsheets.Values.batchGet(spreadsheetId, {
      ranges: ranges,
    });
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", err.message);
  }
};

জাভা

শীট/স্নিপেট/src/main/java/BatchGetValues.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.BatchGetValuesResponse;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Spreadsheet Batch Get Values API */
public class BatchGetValues {
  /**
   * Returns one or more ranges of values from a spreadsheet.
   *
   * @param spreadsheetId - Id of the spreadsheet.
   * @param ranges        - Range of cells of the spreadsheet.
   * @return Values in the range
   * @throws IOException - if credentials file not found.
   */
  public static BatchGetValuesResponse batchGetValues(String spreadsheetId,
                                                      List<String> ranges)
      throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the sheets API client
    Sheets service = new Sheets.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Sheets samples")
        .build();

    BatchGetValuesResponse result = null;
    try {
      // Gets the values of the cells in the specified range.
      result = service.spreadsheets().values().batchGet(spreadsheetId)
          .setRanges(ranges).execute();
      System.out.printf("%d ranges retrieved.", result.getValueRanges().size());
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 404) {
        System.out.printf("Spreadsheet not found with id '%s'.\n", spreadsheetId);
      } else {
        throw e;
      }
    }
    return result;
  }
}

জাভাস্ক্রিপ্ট

শিট/স্নিপেট/শিট_ব্যাচ_গেট_ভ্যালু.জেএস
function batchGetValues(spreadsheetId, _ranges, callback) {
  let ranges = [
    // Range names ...
  ];
  ranges = _ranges;
  try {
    gapi.client.sheets.spreadsheets.values.batchGet({
      spreadsheetId: spreadsheetId,
      ranges: ranges,
    }).then((response) => {
      const result = response.result;
      console.log(`${result.valueRanges.length} ranges retrieved.`);
      if (callback) callback(response);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

নোড.জেএস

শিট/স্নিপেট/শিট_ব্যাচ_গেট_ভ্যালু.জেএস
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Batch gets cell values from a spreadsheet.
 * @param {string} spreadsheetId The ID of the spreadsheet.
 * @param {string} _ranges The ranges of cells to retrieve.
 * @return {obj} The spreadsheet information.
 */
async function batchGetValues(spreadsheetId, _ranges) {
  // Authenticate with Google and get an authorized client.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/spreadsheets',
  });

  // Create a new Sheets API client.
  const service = google.sheets({version: 'v4', auth});

  // The ranges to retrieve from the spreadsheet.
  let ranges = [
    // e.g., 'Sheet1!A1:C5',
    // 'Sheet2!A1:B3'
  ];

পিএইচপি

শীট/স্নিপেট/src/স্প্রেডশিটব্যাচগেটভ্যালুজ.পিএইচপি
<?php

use Google\Client;
use Google\Service\Drive;
use Google\Service\Sheets;
/**
 * method to get a spreadsheet values in batch
 */

function batchGetValues($spreadsheetId)
    {
        /* Load pre-authorized user credentials from the environment.
        TODO(developer) - See https://developers.google.com/identity for
        guides on implementing OAuth2 for your application. */       
        $client = new Google\Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Google\Service\Drive::DRIVE);
        $service = new Google_Service_Sheets($client);
        try{
            $ranges = 'Sheet1!A1:B2';
            $params = array(
                'ranges' => $ranges
            );
            //execute the request
            $result = $service->spreadsheets_values->batchGet($spreadsheetId, $params);
            printf("%d ranges retrieved.", count($result->getValueRanges()));
            return $result;
        }
        catch(Exception $e) {
            // TODO(developer) - handle error appropriately
            echo 'Message: ' .$e->getMessage();
          }
        }

পাইথন

শিট/স্নিপেট/শিট_ব্যাচ_গেট_ভ্যালু.পি
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def batch_get_values(spreadsheet_id, _range_names):
  """
  Creates the batch_update the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    service = build("sheets", "v4", credentials=creds)
    range_names = [
        # Range names ...
    ]
    result = (
        service.spreadsheets()
        .values()
        .batchGet(spreadsheetId=spreadsheet_id, ranges=range_names)
        .execute()
    )
    ranges = result.get("valueRanges", [])
    print(f"{len(ranges)} ranges retrieved")
    return result
  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Pass: spreadsheet_id, and range_name

  batch_get_values("1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k", "A1:C2")

রুবি

শিট/স্নিপেট/লিব/স্প্রেডশিট_স্নিপেটস.আরবি
range_names = [
  # Range names ...
]
result = service.batch_get_spreadsheet_values(spreadsheet_id,
                                              ranges: range_names)
puts "#{result.value_ranges.length} ranges retrieved."

এই অনুরোধের প্রতিক্রিয়াটি একটি BatchGetValuesResponse অবজেক্ট হিসাবে ফেরত পাঠানো হয় যাতে spreadsheetId এবং ValueRange অবজেক্টের একটি তালিকা থাকে।

লিখুন

একটি শীটে লেখার জন্য, আপনার স্প্রেডশিট আইডি, A1 নোটেশনে থাকা কোষের পরিসর এবং একটি উপযুক্ত অনুরোধ বডি অবজেক্টের মধ্যে আপনি যে ডেটা লিখতে চান তা প্রয়োজন। স্প্রেডশিট আইডি এবং A1 নোটেশন সম্পর্কে আরও তথ্যের জন্য, Google Sheets API ওভারভিউ দেখুন।

আপডেটের জন্য একটি বৈধ ValueInputOption প্যারামিটার প্রয়োজন। একক আপডেটের জন্য, এটি একটি প্রয়োজনীয় কোয়েরি প্যারামিটার। ব্যাচ আপডেটের জন্য, এই প্যারামিটারটি অনুরোধের বডিতে প্রয়োজন। ValueInputOption নিয়ন্ত্রণ করে কিভাবে ইনপুট ডেটা ব্যাখ্যা করা উচিত এবং ইনপুট স্ট্রিংগুলি পার্স করা হবে কিনা, যেমনটি নিম্নলিখিত টেবিলে বর্ণিত হয়েছে:

ValueInputOption বিবরণ
RAW ইনপুটটি পার্স করা হয় না এবং একটি স্ট্রিং হিসেবে ঢোকানো হয়। উদাহরণস্বরূপ, ইনপুট "=1+2" কোষে সূত্র নয়, স্ট্রিংটিকে "=1+2" রাখে। (বুলিয়ান বা সংখ্যার মতো নন-স্ট্রিং মানগুলি সর্বদা RAW হিসেবে পরিচালিত হয়।)
USER_ENTERED ইনপুটটি ঠিক এমনভাবে পার্স করা হয় যেন এটি শীট UI-তে প্রবেশ করানো হয়েছে। উদাহরণস্বরূপ, "মার্চ 1 2016" একটি তারিখ হয়ে যায় এবং "=1+2" একটি সূত্র হয়ে যায়। ফর্ম্যাটগুলিও অনুমান করা যেতে পারে, তাই "$100.15" মুদ্রা ফর্ম্যাটিংয়ের সাথে একটি সংখ্যা হয়ে যায়।

সিঙ্গুলার এবং ব্যাচ আপডেট পদ্ধতিগুলি নীচে বর্ণনা করা হয়েছে। মৌলিক লেখার ক্রিয়াকলাপের নমুনার জন্য, মৌলিক লেখা দেখুন।

একটি একক পরিসরে লিখুন

একটি একক পরিসরে ডেটা লেখার জন্য, একটি spreadsheets.values.update অনুরোধ ব্যবহার করুন:

অ্যাপস স্ক্রিপ্ট

শিটস/এপিআই/স্প্রেডশিট_স্নিপেটস.জিএস
/**
 * Updates the values in the specified range
 * @param {string} spreadsheetId spreadsheet's ID
 * @param {string} range the range of cells in spreadsheet
 * @param {string} valueInputOption determines how the input should be interpreted
 * @see
 * https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
 * @param {list<list<string>>} _values list of string lists to input
 * @returns {*} spreadsheet with updated values
 */
Snippets.prototype.updateValues = (
  spreadsheetId,
  range,
  valueInputOption,
  _values,
) => {
  // This code uses the Sheets Advanced Service, but for most use cases
  // the built-in method SpreadsheetApp.getActiveSpreadsheet()
  //     .getRange(range).setValues(values) is more appropriate.
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];

  try {
    const valueRange = Sheets.newValueRange();
    valueRange.values = values;
    const result = Sheets.Spreadsheets.Values.update(
      valueRange,
      spreadsheetId,
      range,
      { valueInputOption: valueInputOption },
    );
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", err.message);
  }
};

জাভা

শীট/স্নিপেট/src/main/java/UpdateValues.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.UpdateValuesResponse;
import com.google.api.services.sheets.v4.model.ValueRange;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Spreadsheet Update Values API */
public class UpdateValues {
  /**
   * Sets values in a range of a spreadsheet.
   *
   * @param spreadsheetId    - Id of the spreadsheet.
   * @param range            - Range of cells of the spreadsheet.
   * @param valueInputOption - Determines how input data should be interpreted.
   * @param values           - List of rows of values to input.
   * @return spreadsheet with updated values
   * @throws IOException - if credentials file not found.
   */
  public static UpdateValuesResponse updateValues(String spreadsheetId,
                                                  String range,
                                                  String valueInputOption,
                                                  List<List<Object>> values)
      throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the sheets API client
    Sheets service = new Sheets.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Sheets samples")
        .build();

    UpdateValuesResponse result = null;
    try {
      // Updates the values in the specified range.
      ValueRange body = new ValueRange()
          .setValues(values);
      result = service.spreadsheets().values().update(spreadsheetId, range, body)
          .setValueInputOption(valueInputOption)
          .execute();
      System.out.printf("%d cells updated.", result.getUpdatedCells());
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 404) {
        System.out.printf("Spreadsheet not found with id '%s'.\n", spreadsheetId);
      } else {
        throw e;
      }
    }
    return result;
  }
}

জাভাস্ক্রিপ্ট

শিট/স্নিপেট/শিট_আপডেট_ভ্যালু.জেএস
function updateValues(spreadsheetId, range, valueInputOption, _values, callback) {
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];
  values = _values;
  const body = {
    values: values,
  };
  try {
    gapi.client.sheets.spreadsheets.values.update({
      spreadsheetId: spreadsheetId,
      range: range,
      valueInputOption: valueInputOption,
      resource: body,
    }).then((response) => {
      const result = response.result;
      console.log(`${result.updatedCells} cells updated.`);
      if (callback) callback(response);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

নোড.জেএস

শিট/স্নিপেট/শিট_আপডেট_ভ্যালু.জেএস
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Updates values in a spreadsheet.
 * @param {string} spreadsheetId The ID of the spreadsheet to update.
 * @param {string} range The range of cells to update.
 * @param {string} valueInputOption How the input data should be interpreted.
 * @param {(string[])[]} _values A 2D array of values to update.
 * @return {Promise<object>} The response from the update request.
 */
async function updateValues(spreadsheetId, range, valueInputOption, _values) {
  // Authenticate with Google and get an authorized client.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/spreadsheets',
  });

  // Create a new Sheets API client.
  const service = google.sheets({version: 'v4', auth});

  // The values to update in the spreadsheet.
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];

  // Create the request body.
  const resource = {
    values,
  };

  // Update the values in the spreadsheet.
  const result = await service.spreadsheets.values.update({
    spreadsheetId,
    range,
    valueInputOption,
    resource,
  });

  // Log the number of updated cells.
  console.log('%d cells updated.', result.data.updatedCells);
  return result;
}

পিএইচপি

শীট/স্নিপেট/src/স্প্রেডশিটআপডেটভ্যালু.php
<?php
use Google\Client;
use Google\Service\Drive;
use Google\Service\Sheets\ValueRange;


function updateValues($spreadsheetId, $range, $valueInputOption)
    {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
        $client = new Google\Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Google\Service\Drive::DRIVE);
        $service = new Google_Service_Sheets($client);
        try{
        $values = [["sample", 'values']];

        $body = new Google_Service_Sheets_ValueRange([
            'values' => $values
        ]);
        $params = [
            'valueInputOption' => $valueInputOption
        ];
        //executing the request
        $result = $service->spreadsheets_values->update($spreadsheetId, $range,
        $body, $params);
        printf("%d cells updated.", $result->getUpdatedCells());
        return $result;
    }
    catch(Exception $e) {
            // TODO(developer) - handle error appropriately
            echo 'Message: ' .$e->getMessage();
          }
    }

পাইথন

শীট/স্নিপেট/শীট_আপডেট_ভ্যালু.পি
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def update_values(spreadsheet_id, range_name, value_input_option, _values):
  """
  Creates the batch_update the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    service = build("sheets", "v4", credentials=creds)
    values = [
        [
            # Cell values ...
        ],
        # Additional rows ...
    ]
    body = {"values": values}
    result = (
        service.spreadsheets()
        .values()
        .update(
            spreadsheetId=spreadsheet_id,
            range=range_name,
            valueInputOption=value_input_option,
            body=body,
        )
        .execute()
    )
    print(f"{result.get('updatedCells')} cells updated.")
    return result
  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Pass: spreadsheet_id,  range_name, value_input_option and  _values
  update_values(
      "1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k",
      "A1:C2",
      "USER_ENTERED",
      [["A", "B"], ["C", "D"]],
  )

রুবি

শিট/স্নিপেট/লিব/স্প্রেডশিট_স্নিপেটস.আরবি
values = [
  [
    # Cell values ...
  ]
  # Additional rows ...
]
data = [
  {
    range:  range_name,
    values: values
  },
  # Additional ranges to update ...
]
value_range_object = Google::Apis::SheetsV4::ValueRange.new(range:  range_name,
                                                            values: values)
result = service.update_spreadsheet_value(spreadsheet_id,
                                          range_name,
                                          value_range_object,
                                          value_input_option: value_input_option)
puts "#{result.updated_cells} cells updated."

আপডেট অনুরোধের মূল অংশটি অবশ্যই একটি ValueRange অবজেক্ট হতে হবে, যদিও শুধুমাত্র প্রয়োজনীয় ক্ষেত্র হল values । যদি range নির্দিষ্ট করা থাকে, তাহলে এটি URL-এর পরিসরের সাথে মিলবে। ValueRange এ, আপনি ঐচ্ছিকভাবে এর majorDimension নির্দিষ্ট করতে পারেন। ডিফল্টরূপে, ROWS ব্যবহার করা হয়। যদি COLUMNS নির্দিষ্ট করা থাকে, তাহলে প্রতিটি অভ্যন্তরীণ অ্যারে একটি সারির পরিবর্তে একটি কলামে লেখা হয়।

আপডেট করার সময়, কোনও ডেটা ছাড়াই মানগুলি এড়িয়ে যায়। ডেটা সাফ করতে, একটি খালি স্ট্রিং ("") ব্যবহার করুন।

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

যদি আপনি একাধিক বিচ্ছিন্ন রেঞ্জ লিখতে চান, তাহলে আপনি একটি spreadsheets.values.batchUpdate অনুরোধ ব্যবহার করতে পারেন:

অ্যাপস স্ক্রিপ্ট

শিটস/এপিআই/স্প্রেডশিট_স্নিপেটস.জিএস
/**
 * Updates the values in the specified range
 * @param {string} spreadsheetId spreadsheet's ID
 * @param {string} range range of cells of the spreadsheet
 * @param {string} valueInputOption determines how the input should be interpreted
 * @see
 * https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
 * @param {list<list<string>>} _values list of string values to input
 * @returns {*} spreadsheet with updated values
 */
Snippets.prototype.batchUpdateValues = (
  spreadsheetId,
  range,
  valueInputOption,
  _values,
) => {
  // This code uses the Sheets Advanced Service, but for most use cases
  // the built-in method SpreadsheetApp.getActiveSpreadsheet()
  //     .getRange(range).setValues(values) is more appropriate.
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];

  try {
    const valueRange = Sheets.newValueRange();
    valueRange.range = range;
    valueRange.values = values;

    const batchUpdateRequest = Sheets.newBatchUpdateValuesRequest();
    batchUpdateRequest.data = valueRange;
    batchUpdateRequest.valueInputOption = valueInputOption;

    const result = Sheets.Spreadsheets.Values.batchUpdate(
      batchUpdateRequest,
      spreadsheetId,
    );
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", err.message);
  }
};

জাভা

শীট/স্নিপেট/src/main/java/BatchUpdateValues.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.BatchUpdateValuesRequest;
import com.google.api.services.sheets.v4.model.BatchUpdateValuesResponse;
import com.google.api.services.sheets.v4.model.ValueRange;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Spreadsheet Batch Update Values API */
public class BatchUpdateValues {
  /**
   * Set values in one or more ranges of spreadsheet.
   *
   * @param spreadsheetId    - Id of the spreadsheet.
   * @param range            - Range of cells of the spreadsheet.
   * @param valueInputOption - Determines how input data should be interpreted.
   * @param values           - list of rows of values to input.
   * @return spreadsheet with updated values
   * @throws IOException - if credentials file not found.
   */
  public static BatchUpdateValuesResponse batchUpdateValues(String spreadsheetId,
                                                            String range,
                                                            String valueInputOption,
                                                            List<List<Object>> values)
      throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the sheets API client
    Sheets service = new Sheets.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Sheets samples")
        .build();

    List<ValueRange> data = new ArrayList<>();
    data.add(new ValueRange()
        .setRange(range)
        .setValues(values));

    BatchUpdateValuesResponse result = null;
    try {
      // Updates the values in the specified range.
      BatchUpdateValuesRequest body = new BatchUpdateValuesRequest()
          .setValueInputOption(valueInputOption)
          .setData(data);
      result = service.spreadsheets().values().batchUpdate(spreadsheetId, body).execute();
      System.out.printf("%d cells updated.", result.getTotalUpdatedCells());
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 404) {
        System.out.printf("Spreadsheet not found with id '%s'.\n", spreadsheetId);
      } else {
        throw e;
      }
    }
    return result;
  }
}

জাভাস্ক্রিপ্ট

শিট/স্নিপেট/শিট_ব্যাচ_আপডেট_ভ্যালু.জেএস
function batchUpdateValues(spreadsheetId, range, valueInputOption, _values, callback) {
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];
  values = _values;
  const data = [];
  data.push({
    range: range,
    values: values,
  });
  // Additional ranges to update.

  const body = {
    data: data,
    valueInputOption: valueInputOption,
  };
  try {
    gapi.client.sheets.spreadsheets.values.batchUpdate({
      spreadsheetId: spreadsheetId,
      resource: body,
    }).then((response) => {
      const result = response.result;
      console.log(`${result.totalUpdatedCells} cells updated.`);
      if (callback) callback(response);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

নোড.জেএস

শিট/স্নিপেট/শিট_ব্যাচ_আপডেট_ভ্যালু.জেএস
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Batch updates values in a spreadsheet.
 * @param {string} spreadsheetId The ID of the spreadsheet to update.
 * @param {string} range The range of cells to update.
 * @param {string} valueInputOption How the input data should be interpreted.
 * @param {(string[])[]} _values A 2D array of values to update.
 * @return {Promise<object>} The response from the batch update.
 */
async function batchUpdateValues(
  spreadsheetId,
  range,
  valueInputOption,
  _values,
) {
  // Authenticate with Google and get an authorized client.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/spreadsheets',
  });

  // Create a new Sheets API client.
  const service = google.sheets({version: 'v4', auth});

  // The values to update in the spreadsheet.
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];

  // The data to be updated.
  const data = [
    {
      range,
      values,
    },
  ];

  // Additional ranges to update can be added here.

  // Create the batch update request.
  const resource = {
    data,
    valueInputOption,
  };

  // Execute the batch update request.
  const result = await service.spreadsheets.values.batchUpdate({
    spreadsheetId,
    resource,
  });

  // Log the number of updated cells.
  console.log('%d cells updated.', result.data.totalUpdatedCells);
  return result;
}

পিএইচপি

শীট/স্নিপেট/src/স্প্রেডশিটব্যাচআপডেটভ্যালু.পিএইচপি
<?php
/**
 * to update values in batch for a particular spreadsheet
 */
use Google\Client;
use Google\Service\Drive;
use Google\Service\Sheets;

function batchUpdateValues($spreadsheetId, $range, $valueInputOption)
    {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
        $client = new Google\Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Google\Service\Drive::DRIVE);
        $service = new Google_Service_Sheets($client);
        $values = [];
        try{

            $data[] = new Google_Service_Sheets_ValueRange([
                'range' => $range,
            'values' => $values
        ]);
        $body = new Google_Service_Sheets_BatchUpdateValuesRequest([
            'valueInputOption' => $valueInputOption,
            'data' => $data
        ]);
        $result = $service->spreadsheets_values->batchUpdate($spreadsheetId, $body);
        printf("%d cells updated.", $result->getTotalUpdatedCells());
        return $result;
    }

        catch(Exception $e) {
            // TODO(developer) - handle error appropriately
            echo 'Message: ' .$e->getMessage();
          }
    }

পাইথন

শীট/স্নিপেট/শীট_ব্যাচ_আপডেট_ভ্যালু.পিআই
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def batch_update_values(
    spreadsheet_id, range_name, value_input_option, _values
):
  """
  Creates the batch_update the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    service = build("sheets", "v4", credentials=creds)

    values = [
        [
            # Cell values ...
        ],
        # Additional rows
    ]
    data = [
        {"range": range_name, "values": values},
        # Additional ranges to update ...
    ]
    body = {"valueInputOption": value_input_option, "data": data}
    result = (
        service.spreadsheets()
        .values()
        .batchUpdate(spreadsheetId=spreadsheet_id, body=body)
        .execute()
    )
    print(f"{(result.get('totalUpdatedCells'))} cells updated.")
    return result
  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Pass: spreadsheet_id, range_name value_input_option and _values)
  batch_update_values(
      "1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k",
      "A1:C2",
      "USER_ENTERED",
      [["F", "B"], ["C", "D"]],
  )

রুবি

শিট/স্নিপেট/লিব/স্প্রেডশিট_স্নিপেটস.আরবি
values = [
  [
    # Cell values ...
  ]
  # Additional rows ...
]
data = [
  {
    range:  range_name,
    values: values
  },
  # Additional ranges to update ...
]
batch_update_values = Google::Apis::SheetsV4::BatchUpdateValuesRequest.new(
  data:               data,
  value_input_option: value_input_option
)
result = service.batch_update_values(spreadsheet_id, batch_update_values)
puts "#{result.total_updated_cells} cells updated."

ব্যাচ আপডেট অনুরোধের মূল অংশটি অবশ্যই একটি BatchUpdateValuesRequest অবজেক্ট হতে হবে, যাতে একটি ValueInputOption এবং ValueRange অবজেক্টের একটি তালিকা থাকবে (প্রতিটি লিখিত পরিসরের জন্য একটি)। প্রতিটি ValueRange অবজেক্ট তার নিজস্ব range , majorDimension এবং ইনপুট ডেটা নির্দিষ্ট করে।

মান যোগ করুন

একটি শিটে ডেটা টেবিলের পরে ডেটা যুক্ত করতে, একটি spreadsheets.values.append অনুরোধ ব্যবহার করুন:

অ্যাপস স্ক্রিপ্ট

শিটস/এপিআই/স্প্রেডশিট_স্নিপেটস.জিএস
/**
 * Appends values to the specified range
 * @param {string} spreadsheetId spreadsheet's ID
 * @param {string} range range of cells in the spreadsheet
 * @param valueInputOption determines how the input should be interpreted
 * @see
 * https://developers.google.com/sheets/api/reference/rest/v4/ValueInputOption
 * @param {list<string>} _values list of rows of values to input
 * @returns {*} spreadsheet with appended values
 */
Snippets.prototype.appendValues = (
  spreadsheetId,
  range,
  valueInputOption,
  _values,
) => {
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];
  try {
    const valueRange = Sheets.newRowData();
    valueRange.values = values;

    const appendRequest = Sheets.newAppendCellsRequest();
    appendRequest.sheetId = spreadsheetId;
    appendRequest.rows = [valueRange];

    const result = Sheets.Spreadsheets.Values.append(
      valueRange,
      spreadsheetId,
      range,
      { valueInputOption: valueInputOption },
    );
    return result;
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log("Failed with error %s", err.message);
  }
};

জাভা

শীট/স্নিপেট/src/main/java/AppendValues.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.sheets.v4.Sheets;
import com.google.api.services.sheets.v4.SheetsScopes;
import com.google.api.services.sheets.v4.model.AppendValuesResponse;
import com.google.api.services.sheets.v4.model.ValueRange;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

/* Class to demonstrate the use of Spreadsheet Append Values API */
public class AppendValues {
  /**
   * Appends values to a spreadsheet.
   *
   * @param spreadsheetId    - Id of the spreadsheet.
   * @param range            - Range of cells of the spreadsheet.
   * @param valueInputOption - Determines how input data should be interpreted.
   * @param values           - list of rows of values to input.
   * @return spreadsheet with appended values
   * @throws IOException - if credentials file not found.
   */
  public static AppendValuesResponse appendValues(String spreadsheetId,
                                                  String range,
                                                  String valueInputOption,
                                                  List<List<Object>> values)
      throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(Collections.singleton(SheetsScopes.SPREADSHEETS));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Create the sheets API client
    Sheets service = new Sheets.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Sheets samples")
        .build();

    AppendValuesResponse result = null;
    try {
      // Append values to the specified range.
      ValueRange body = new ValueRange()
          .setValues(values);
      result = service.spreadsheets().values().append(spreadsheetId, range, body)
          .setValueInputOption(valueInputOption)
          .execute();
      // Prints the spreadsheet with appended values.
      System.out.printf("%d cells appended.", result.getUpdates().getUpdatedCells());
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 404) {
        System.out.printf("Spreadsheet not found with id '%s'.\n", spreadsheetId);
      } else {
        throw e;
      }
    }
    return result;
  }
}

জাভাস্ক্রিপ্ট

শিট/স্নিপেট/শিট_অ্যাপেন্ড_ভ্যালু.জেএস
function appendValues(spreadsheetId, range, valueInputOption, _values, callback) {
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];
  values = _values;
  const body = {
    values: values,
  };
  try {
    gapi.client.sheets.spreadsheets.values.append({
      spreadsheetId: spreadsheetId,
      range: range,
      valueInputOption: valueInputOption,
      resource: body,
    }).then((response) => {
      const result = response.result;
      console.log(`${result.updates.updatedCells} cells appended.`);
      if (callback) callback(response);
    });
  } catch (err) {
    document.getElementById('content').innerText = err.message;
    return;
  }
}

নোড.জেএস

শিট/স্নিপেট/শিট_অ্যাপেন্ড_ভ্যালু.জেএস
import {GoogleAuth} from 'google-auth-library';
import {google} from 'googleapis';

/**
 * Appends values to a spreadsheet.
 * @param {string} spreadsheetId The ID of the spreadsheet to update.
 * @param {string} range The range of cells to append to.
 * @param {string} valueInputOption How the input data should be interpreted.
 * @param {(string[])[]} _values A 2D array of values to append.
 * @return {Promise<object>} The response from the append request.
 */
async function appendValues(spreadsheetId, range, valueInputOption, _values) {
  // Authenticate with Google and get an authorized client.
  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/spreadsheets',
  });

  // Create a new Sheets API client.
  const service = google.sheets({version: 'v4', auth});

  // The values to append to the spreadsheet.
  let values = [
    [
      // Cell values ...
    ],
    // Additional rows ...
  ];

  // Create the request body.
  const resource = {
    values,
  };

  // Append the values to the spreadsheet.
  const result = await service.spreadsheets.values.append({
    spreadsheetId,
    range,
    valueInputOption,
    resource,
  });

  // Log the number of appended cells.
  console.log(`${result.data.updates.updatedCells} cells appended.`);
  return result;
}

পিএইচপি

শীট/স্নিপেট/src/স্প্রেডশিটঅ্যাপেন্ডভ্যালু.php
<?php
use Google\Client;
use Google\Service\Sheets;


function appendValues($spreadsheetId, $range, $valueInputOption)
{
    /* Load pre-authorized user credentials from the environment.
       TODO(developer) - See https://developers.google.com/identity for
        guides on implementing OAuth2 for your application. */
    $client = new Google\Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope('https://www.googleapis.com/auth/spreadsheets');
    $service = new Google\Service\Sheets($client);
    try {
        $values = []; //add the values to be appended
        //execute the request
        $body = new Google_Service_Sheets_ValueRange([
            'values' => $values
        ]);
        $params = [
            'valueInputOption' => $valueInputOption
        ];
        $result = $service->spreadsheets_values->append($spreadsheetId, $range, $body, $params);
        printf("%d cells appended.", $result->getUpdates()->getUpdatedCells());
        return $result;
    } catch (Exception $e) {
        // TODO(developer) - handle error appropriately
        echo 'Message: ' . $e->getMessage();
    }

পাইথন

শীট/স্নিপেট/শীট_অ্যাপেন্ড_ভ্যালু.পি
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def append_values(spreadsheet_id, range_name, value_input_option, _values):
  """
  Creates the batch_update the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  try:
    service = build("sheets", "v4", credentials=creds)

    values = [
        [
            # Cell values ...
        ],
        # Additional rows ...
    ]
    body = {"values": values}
    result = (
        service.spreadsheets()
        .values()
        .append(
            spreadsheetId=spreadsheet_id,
            range=range_name,
            valueInputOption=value_input_option,
            body=body,
        )
        .execute()
    )
    print(f"{(result.get('updates').get('updatedCells'))} cells appended.")
    return result

  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Pass: spreadsheet_id, range_name value_input_option and _values)
  append_values(
      "1CM29gwKIzeXsAppeNwrc8lbYaVMmUclprLuLYuHog4k",
      "A1:C2",
      "USER_ENTERED",
      [["F", "B"], ["C", "D"]],
  )

রুবি

শিট/স্নিপেট/লিব/স্প্রেডশিট_স্নিপেটস.আরবি
values = [
  [
    # Cell values ...
  ],
  # Additional rows ...
]
value_range = Google::Apis::SheetsV4::ValueRange.new(values: values)
result = service.append_spreadsheet_value(spreadsheet_id,
                                          range_name,
                                          value_range,
                                          value_input_option: value_input_option)
puts "#{result.updates.updated_cells} cells appended."

আপডেট অনুরোধের মূল অংশটি অবশ্যই একটি ValueRange অবজেক্ট হতে হবে, যদিও শুধুমাত্র প্রয়োজনীয় ক্ষেত্র হল values । যদি range নির্দিষ্ট করা থাকে, তাহলে এটি URL-এর পরিসরের সাথে মিলবে। ValueRange এ, আপনি ঐচ্ছিকভাবে এর majorDimension নির্দিষ্ট করতে পারেন। ডিফল্টরূপে, ROWS ব্যবহার করা হয়। যদি COLUMNS নির্দিষ্ট করা থাকে, তাহলে প্রতিটি অভ্যন্তরীণ অ্যারে একটি সারির পরিবর্তে একটি কলামে লেখা হয়।

ইনপুট রেঞ্জটি বিদ্যমান ডেটা অনুসন্ধান করতে এবং সেই রেঞ্জের মধ্যে একটি "টেবিল" খুঁজে পেতে ব্যবহৃত হয়। মানগুলি টেবিলের পরবর্তী সারিতে যুক্ত করা হয়, টেবিলের প্রথম কলাম থেকে শুরু করে। উদাহরণস্বরূপ, Sheet1 বিবেচনা করুন যা দেখতে এরকম:

এক্স y z-এর
এক্স y z-এর
এক্স y
y z-এর
এক্স y z-এর

শিটে দুটি টেবিল আছে: A1:C2 , এবং B4:D6 । নিম্নলিখিত সমস্ত range ইনপুটের জন্য সংযুক্ত মানগুলি B7 থেকে শুরু হবে:

  • Sheet1 , কারণ এটি শীটের সমস্ত ডেটা পরীক্ষা করবে এবং নির্ধারণ করবে যে B4:D6 এর টেবিলটি শেষ টেবিল।
  • B4 অথবা C5:D5 , কারণ তারা উভয়ই B4:D6 টেবিলে রয়েছে।
  • B2:D4 , কারণ পরিসরের শেষ টেবিলটি হল B4:D6 টেবিল (যদিও এতে A1:C2 টেবিলও রয়েছে)।
  • A3:G10 , কারণ পরিসরের শেষ টেবিলটি হল B4:D6 টেবিল (যদিও এটি আগে থেকে শুরু হয়ে পরে শেষ হয়)।

নিম্নলিখিত range ইনপুটগুলি B7 এ লেখা শুরু করবে না:

  • A1 A3 থেকে লেখা শুরু করবে, কারণ এটি A1:C2 টেবিলে রয়েছে।
  • E4 E4 থেকে লেখা শুরু করবে, কারণ এটি কোনও টেবিলে নেই। ( A4 একই কারণে A4 থেকেও লেখা শুরু করবে।)

অতিরিক্তভাবে, আপনি একটি টেবিলের পরে বিদ্যমান ডেটা ওভাররাইট করতে চান নাকি নতুন ডেটার জন্য নতুন সারি সন্নিবেশ করতে চান তা বেছে নিতে পারেন। ডিফল্টরূপে, ইনপুট টেবিলের পরে ডেটা ওভাররাইট করে। নতুন ডেটা নতুন সারিতে লিখতে, InsertDataOption ব্যবহার করুন এবং insertDataOption=INSERT_ROWS উল্লেখ করুন।

পত্রকগুলিতে ঘর এবং সারি সীমা সম্পর্কে আরও জানতে, Google ড্রাইভে আপনি যে ফাইলগুলি সংরক্ষণ করতে পারেন তা দেখুন।