Updating specific row in iOS Swift using Google SpreadSheet API

后端 未结 1 484
失恋的感觉
失恋的感觉 2021-01-23 16:00

I have been working on Google SpreadSheet API in iOS swift, but theres a problem in updating a specific field in SpreadSheet row/data in iOS Swift,

Following is the code

相关标签:
1条回答
  • 2021-01-23 16:21

    You should define an exact range for a cell you are going to update. It might look like this:

    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)
    
    }
    

    And don't forget to define a right scope in GIDSignIn.sharedInstance().scopes

    0 讨论(0)
提交回复
热议问题