代码之家  ›  专栏  ›  技术社区  ›  vico

不允许在谷歌电子表格中重复

  •  0
  • vico  · 技术社区  · 6 年前

    我使用谷歌电子表格一样的数据库表,希望第一个字段是唯一的。如何在更新前检查字段唯一性。或者我可以设置列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();
    
        }
    
    0 回复  |  直到 6 年前