我正在使用Google电子表格(例如数据库表),并且希望第一个字段是唯一的。如何在更新前检查字段唯一。还是我可以以某种方式将A列设置为不允许唯一字段?
我正在使用C#处理电子表格:
private void button3_Click(object sender, EventArgs e)
{
string spreadsheetId = "1IAD2okAWZD7anbt5L4ybgD2dxHBGmsY6IkNIWHBQkBM";
string ApplicationName = "sheets";
UserCredential credential;
using (var stream = new FileStream("credentials_1.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.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,
});
String range = "new first sheet!A1"; // mano
//var range = "{sheet}!D543";
var valueRange = new ValueRange();
var oblist = new List<object>() { "aaa","bbb","ccc" };
valueRange.Values = new List<IList<object>> { oblist };
var updateRequest = service.Spreadsheets.Values.Append(valueRange, spreadsheetId, range);
updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
var appendReponse = updateRequest.Execute();
}