使用Google.Apis.Sheets.v4更新指定单元格时出现定位错误求助
Google Sheets API单元格更新定位错误问题
在C#中使用Google.Apis.Sheets.v4库操作Google表格时,遇到单元格更新定位错误:尝试向特定单元格追加值时,值却被写入A列最后未使用的行。目前可以正常更新AK15单元格,但更新AK6、AK5、AJ4时每次都会出现此问题,此前已成功更新AI-AL列的50+个单元格。请问有开发者遇到过类似问题吗?
相关代码
UserCredential credential; using (var stream = new FileStream(ReadXMLFileForSettings.Configs["gCredLocation"], FileMode.Open, FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = ReadXMLFileForSettings.Configs["TokenLocation"]; credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)); } // Create Google Sheets API service. var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Check Underperformance VAs" }); int counter = 0; foreach (var monthCounter in MonthCounters) { int row = monthCounter.batch - 65; //get the column Letter based on int column = (monthCounter.year - 2022) * 12; string columnLetter = string.Empty; while (column > 0) { column--; // Decrement to make it 0-indexed columnLetter = (char)(column % 26 + 'A') + columnLetter; column /= 26; } string Cell = "Underperformance Heat Map!" + columnLetter + row; counter++; var newValue = new ValueRange() { Values = new[] { new[] { counter.ToString() } } }; var updateRequest = service.Spreadsheets.Values.Append(newValue, SpreadsheetId, Cell); updateRequest.ValueInputOption = (SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum?)SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; // Get the response from the update request var result = await updateRequest.ExecuteAsync().ConfigureAwait(false); Logging.WriteToLog($"Updated {Cell} - {counter}"); }
内容的提问来源于stack exchange,提问作者Meneghini
相关产品推荐
相关产品推荐

