Có ai có ví dụ C# tốt để cập nhật ô bằng API v4 không?Google Trang tính API v4 C# cập nhật ô
Tôi có ví dụ lấy mẫu C# ví dụ từ trang web nhà phát triển làm việc với API Google Trang tính v4. Tôi đang cố sửa đổi ví dụ để cập nhật một ô có giá trị là "Tom". Tôi bị kẹt trong cài đặt cho SpreadSheets.Values.Update.
using Google.Apis.Auth.OAuth2;
using Google.Apis.Sheets.v4;
using Google.Apis.Sheets.v4.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace GoogleSheetsAPI4_v1console
{
class Program
{
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/sheets.googleapis.com-dotnet-quickstart.json
static string[] Scopes = { SheetsService.Scope.Spreadsheet };
static string ApplicationName = "TestSpreadsheet";
static void Main(string[] args)
{
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Google Sheets API service.
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define request parameters.
String spreadsheetId = "<<myspreadsheetid>>";
String range = "Sheet1!D5"; // single cell D5
String myNewCellValue = "Tom";
SpreadsheetsResource.ValuesResource.UpdateRequest request = service.Spreadsheets.Values.Update(<<what goes here?>>, spreadsheetId, range);
// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
ValueRange response = request.Execute();
IList<IList<Object>> values = response.Values;
Console.WriteLine(values);
}
}
}
Bạn chính xác chắc chắn sẽ không chỉ đọc. Tôi đã thay đổi thành "SheetsService.Scope.Spreadsheet". – Slim
Tôi bị mắc kẹt trên cú pháp cho Spreadsheets.Values.Update (<< những gì diễn ra ở đây? >>, spreadsheetId, phạm vi); các tham số 'bảng tính' và 'dải ô' là các chuỗi, trong khi phiên bản đầu tiên được liệt kê là cần phải là 'nội dung'. – Slim