GTLRSheets_Color not holding value

二次信任 提交于 2020-06-28 09:21:01

问题


I am trying to set a value for "background color" as seen below but when I print the value after setting it, it simply shows nil? This makes absolutely no sense. Please help, I have exhausted all resources already.

Thank you.

let request = GTLRSheets_Request.init()

        request.repeatCell = GTLRSheets_RepeatCellRequest.init()


        let colbox = GTLRSheets_GridRange.init()

            colbox.startRowIndex = rowstart
            colbox.endRowIndex = rowend
            colbox.startColumnIndex = columnstart
            colbox.endColumnIndex = columnend
            request.repeatCell?.range = colbox

        let color = GTLRSheets_Color.init()
            color.blue = 60
            color.red = 47
            color.green = 77

            request.repeatCell?.cell?.userEnteredFormat?.backgroundColor = color
            request.repeatCell?.cell?.userEnteredFormat?.textFormat?.bold = true     
            request.repeatCell?.cell?.userEnteredFormat?.horizontalAlignment = "CENTER"

            request.repeatCell?.fields = "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment)"

            print(request.repeatCell?.cell?.userEnteredFormat?.backgroundColor)

        let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
            batchUpdate.requests = [request]

        let createQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetId)

            service.executeQuery(createQuery) { (ticket, result, NSError) in

                    }

回答1:


Issue:

You should initialize cell and userEnteredFormat.

Solution:

cell refers to an instance of GTLRSheets_CellData, and should be initialized the following way:

request.repeatCell?.cell = GTLRSheets_CellData.init()

userEnteredFormat refers to an instance of GTLRSheets_CellFormat:

request.repeatCell?.cell?.userEnteredFormat = GTLRSheets_CellFormat.init()

Reference:

  • GTLRSheets_CellData
  • GTLRSheets_CellFormat
  • Swift: Initialization


来源:https://stackoverflow.com/questions/62367651/gtlrsheets-color-not-holding-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!