gpt4 book ai didi

ios - 使用 Google SpreadSheet API 更新 iOS Swift 中的特定行

转载 作者:行者123 更新时间:2023-11-30 11:17:56 27 4
gpt4 key购买 nike

我一直在 iOS swift 中开发 Google SpreadSheet API,但是在 iOS Swift 中更新 SpreadSheet 行/数据中的特定字段时出现问题,

以下是在电子表格顶部添加一行的代码,但我想要特定索引或匹配特定值,

  let service = GTLRSheetsService()
service.authorizer = GIDSignIn.sharedInstance().currentUser.authentication.fetcherAuthorizer()
service.apiKey = Constants.GOOGLE_SPEADSHEET_API_KEY
let range = "Employee List!A2:D"
let valueRange = GTLRSheets_ValueRange.init()
valueRange.values = [[job.jobTitle!]] //want to add job title on specific field after maching employee name

let query = GTLRSheetsQuery_SpreadsheetsValuesUpdate.query(withObject: valueRange, spreadsheetId: Constants.SPREAD_SHEET_ID, range: range)
query.valueInputOption = "USER_ENTERED"

service.executeQuery(query) { (ticket, response, error) in
print(response)

}

此代码在 B2 列的顶部添加职位名称,但我想通过检查名称然后根据名称添加职位来将其添加到特定行。

PS:数据如下

Want to add job title by matching the particular employee name, ref to image

有人可以帮我吗?

非常感谢

最佳答案

您应该为要更新的单元格定义一个准确的范围。它可能看起来像这样:

let service = GTLRSheetsService()
service.authorizer = GIDSignIn.sharedInstance().currentUser.authentication.fetcherAuthorizer()
service.apiKey = Constants.GOOGLE_SPEADSHEET_API_KEY
let rowIndex:Int = job.rowIndex
let range = "Employee List!C\(rowIndex):C\(rowIndex)"
let valueRange = GTLRSheets_ValueRange()
valueRange.range = "Employee List!C\(rowIndex):C\(rowIndex)"
valueRange.values = [[job.jobTitle!]]
valueRange.majorDimension = "COLUMNS"

let query = GTLRSheetsQuery_SpreadsheetsValuesUpdate.query(withObject: valueRange, spreadsheetId: Constants.SPREAD_SHEET_ID, range: range)
query.valueInputOption = "USER_ENTERED"

service.executeQuery(query) { (ticket, response, error) in
print(response)

}

并且不要忘记在 GIDSignIn.sharedInstance().scopes 中定义正确的范围

关于ios - 使用 Google SpreadSheet API 更新 iOS Swift 中的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51585042/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com