Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Google Sheets - Create a New SpreadsheetDemonstrates how to create a new and empty spreadsheet.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. # This example uses a previously obtained access token having permission for the # Google Sheets scope. # In this example, Get Google Sheets OAuth2 Access Token, the access # token was saved to a JSON file. This example fetches the access token from the file.. set jsonToken [new_CkJsonObject] set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/googleSheets.json"] if {[CkJsonObject_HasMember $jsonToken "access_token"] == 0} then { puts "No access token found." delete_CkJsonObject $jsonToken exit } set http [new_CkHttp] CkHttp_put_AuthToken $http [CkJsonObject_stringOf $jsonToken "access_token"] # Create the following JSON: # The JSON code can be generated using this online tool: Generate JSON create code # { # "sheets": [ # { # "properties": { # "title": "Sample Tab" # } # } # ], # "properties": { # "title": "Create Spreadsheet using Sheets API v4" # } # } # This code generates the above JSON: set json [new_CkJsonObject] CkJsonObject_UpdateString $json "sheets[0].properties.title" "Sample Tab" CkJsonObject_UpdateString $json "properties.title" "Create Spreadsheet using Sheets API v4" # Send the POST to create the new Google spreadsheet. # resp is a CkHttpResponse set resp [CkHttp_PostJson3 $http "https://sheets.googleapis.com/v4/spreadsheets" "application/json" $json] if {[CkHttp_get_LastMethodSuccess $http] != 1} then { puts [CkHttp_lastErrorText $http] delete_CkJsonObject $jsonToken delete_CkHttp $http delete_CkJsonObject $json exit } puts "response status code = [CkHttpResponse_get_StatusCode $resp]" puts "response JSON:" CkJsonObject_Load $json [CkHttpResponse_bodyStr $resp] CkJsonObject_put_EmitCompact $json 0 puts [CkJsonObject_emit $json] delete_CkHttpResponse $resp # A sample response is shown below. # To generate the parsing source code for a JSON response, paste # the JSON into this online tool: Generate JSON parsing code # { # "spreadsheetId": "1ueEQu3WDBkIAOUhzLnY4zr6JO5SrJx0dQ-YkQlUVYD0", # "properties": { # "title": "Create Spreadsheet using Sheets API v4", # "locale": "en_US", # "autoRecalc": "ON_CHANGE", # "timeZone": "Etc/GMT", # "defaultFormat": { # "backgroundColor": { # "red": 1, # "green": 1, # "blue": 1 # }, # "padding": { # "top": 2, # "right": 3, # "bottom": 2, # "left": 3 # }, # "verticalAlignment": "BOTTOM", # "wrapStrategy": "OVERFLOW_CELL", # "textFormat": { # "foregroundColor": {}, # "fontFamily": "arial,sans,sans-serif", # "fontSize": 10, # "bold": false, # "italic": false, # "strikethrough": false, # "underline": false # } # } # }, # "sheets": [ # { # "properties": { # "sheetId": 1629642057, # "title": "Sample Tab", # "index": 0, # "sheetType": "GRID", # "gridProperties": { # "rowCount": 1000, # "columnCount": 26 # } # } # } # ], # "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1ueEQu3WDBkIAOUhzLnY4zr6JO5SrJx0dQ-YkQlUVYD0/edit" # } # set spreadsheetId [CkJsonObject_stringOf $json "spreadsheetId"] set propertiesTitle [CkJsonObject_stringOf $json "properties.title"] set propertiesLocale [CkJsonObject_stringOf $json "properties.locale"] set propertiesAutoRecalc [CkJsonObject_stringOf $json "properties.autoRecalc"] set propertiesTimeZone [CkJsonObject_stringOf $json "properties.timeZone"] set propertiesDefaultFormatBackgroundColorRed [CkJsonObject_IntOf $json "properties.defaultFormat.backgroundColor.red"] set propertiesDefaultFormatBackgroundColorGreen [CkJsonObject_IntOf $json "properties.defaultFormat.backgroundColor.green"] set propertiesDefaultFormatBackgroundColorBlue [CkJsonObject_IntOf $json "properties.defaultFormat.backgroundColor.blue"] set propertiesDefaultFormatPaddingTop [CkJsonObject_IntOf $json "properties.defaultFormat.padding.top"] set propertiesDefaultFormatPaddingRight [CkJsonObject_IntOf $json "properties.defaultFormat.padding.right"] set propertiesDefaultFormatPaddingBottom [CkJsonObject_IntOf $json "properties.defaultFormat.padding.bottom"] set propertiesDefaultFormatPaddingLeft [CkJsonObject_IntOf $json "properties.defaultFormat.padding.left"] set propertiesDefaultFormatVerticalAlignment [CkJsonObject_stringOf $json "properties.defaultFormat.verticalAlignment"] set propertiesDefaultFormatWrapStrategy [CkJsonObject_stringOf $json "properties.defaultFormat.wrapStrategy"] set propertiesDefaultFormatTextFormatFontFamily [CkJsonObject_stringOf $json "properties.defaultFormat.textFormat.fontFamily"] set propertiesDefaultFormatTextFormatFontSize [CkJsonObject_IntOf $json "properties.defaultFormat.textFormat.fontSize"] set propertiesDefaultFormatTextFormatBold [CkJsonObject_BoolOf $json "properties.defaultFormat.textFormat.bold"] set propertiesDefaultFormatTextFormatItalic [CkJsonObject_BoolOf $json "properties.defaultFormat.textFormat.italic"] set propertiesDefaultFormatTextFormatStrikethrough [CkJsonObject_BoolOf $json "properties.defaultFormat.textFormat.strikethrough"] set propertiesDefaultFormatTextFormatUnderline [CkJsonObject_BoolOf $json "properties.defaultFormat.textFormat.underline"] set spreadsheetUrl [CkJsonObject_stringOf $json "spreadsheetUrl"] set i 0 set count_i [CkJsonObject_SizeOfArray $json "sheets"] while {$i < $count_i} { CkJsonObject_put_I $json $i set propertiesSheetId [CkJsonObject_IntOf $json "sheets[i].properties.sheetId"] set propertiesTitle [CkJsonObject_stringOf $json "sheets[i].properties.title"] set propertiesIndex [CkJsonObject_IntOf $json "sheets[i].properties.index"] set propertiesSheetType [CkJsonObject_stringOf $json "sheets[i].properties.sheetType"] set propertiesGridPropertiesRowCount [CkJsonObject_IntOf $json "sheets[i].properties.gridProperties.rowCount"] set propertiesGridPropertiesColumnCount [CkJsonObject_IntOf $json "sheets[i].properties.gridProperties.columnCount"] set i [expr $i + 1] } delete_CkJsonObject $jsonToken delete_CkHttp $http delete_CkJsonObject $json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.