Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Tcl Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Tcl) Google Sheets - Create a New Spreadsheet

Demonstrates how to create a new and empty spreadsheet.

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

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 {[expr [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 {[expr [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 {[expr $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-2019 Chilkat Software, Inc. All Rights Reserved.