本文介绍了GTLRSheets_Color不具有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为背景色"设置一个值,如下所示,但是当我在设置值后打印该值时,它只是显示nil?这绝对没有道理.请帮助,我已经用尽了所有资源.

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.

谢谢.

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

                    }

推荐答案

问题:

您应该初始化celluserEnteredFormat.

cell GTLRSheets_CellData 的实例. ,并应通过以下方式进行初始化:

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

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

userEnteredFormat GTLRSheets_CellFormat 的实例. :

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

参考:

08-15 00:12