Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C) Google Sheets - Create a New Spreadsheet

Demonstrates how to create a new and empty spreadsheet.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkJsonObject.h>
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkJsonObject jsonToken;
    BOOL success;
    HCkHttp http;
    HCkJsonObject json;
    HCkHttpResponse resp;
    int i;
    int count_i;
    const char *spreadsheetId;
    const char *propertiesTitle;
    const char *propertiesLocale;
    const char *propertiesAutoRecalc;
    const char *propertiesTimeZone;
    int propertiesDefaultFormatBackgroundColorRed;
    int propertiesDefaultFormatBackgroundColorGreen;
    int propertiesDefaultFormatBackgroundColorBlue;
    int propertiesDefaultFormatPaddingTop;
    int propertiesDefaultFormatPaddingRight;
    int propertiesDefaultFormatPaddingBottom;
    int propertiesDefaultFormatPaddingLeft;
    const char *propertiesDefaultFormatVerticalAlignment;
    const char *propertiesDefaultFormatWrapStrategy;
    const char *propertiesDefaultFormatTextFormatFontFamily;
    int propertiesDefaultFormatTextFormatFontSize;
    BOOL propertiesDefaultFormatTextFormatBold;
    BOOL propertiesDefaultFormatTextFormatItalic;
    BOOL propertiesDefaultFormatTextFormatStrikethrough;
    BOOL propertiesDefaultFormatTextFormatUnderline;
    const char *spreadsheetUrl;
    int propertiesSheetId;
    int propertiesIndex;
    const char *propertiesSheetType;
    int propertiesGridPropertiesRowCount;
    int propertiesGridPropertiesColumnCount;

    //  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..
    jsonToken = CkJsonObject_Create();
    success = CkJsonObject_LoadFile(jsonToken,"qa_data/tokens/googleSheets.json");
    if (CkJsonObject_HasMember(jsonToken,"access_token") == FALSE) {
        printf("No access token found.\n");
        CkJsonObject_Dispose(jsonToken);
        return;
    }

    http = CkHttp_Create();
    CkHttp_putAuthToken(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:
    json = CkJsonObject_Create();
    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 = CkHttp_PostJson3(http,"https://sheets.googleapis.com/v4/spreadsheets","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkJsonObject_Dispose(jsonToken);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("response status code = %d\n",CkHttpResponse_getStatusCode(resp));
    printf("response JSON:\n");

    CkJsonObject_Load(json,CkHttpResponse_bodyStr(resp));
    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));

    CkHttpResponse_Dispose(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"
    //  }
    // 

    spreadsheetId = CkJsonObject_stringOf(json,"spreadsheetId");
    propertiesTitle = CkJsonObject_stringOf(json,"properties.title");
    propertiesLocale = CkJsonObject_stringOf(json,"properties.locale");
    propertiesAutoRecalc = CkJsonObject_stringOf(json,"properties.autoRecalc");
    propertiesTimeZone = CkJsonObject_stringOf(json,"properties.timeZone");
    propertiesDefaultFormatBackgroundColorRed = CkJsonObject_IntOf(json,"properties.defaultFormat.backgroundColor.red");
    propertiesDefaultFormatBackgroundColorGreen = CkJsonObject_IntOf(json,"properties.defaultFormat.backgroundColor.green");
    propertiesDefaultFormatBackgroundColorBlue = CkJsonObject_IntOf(json,"properties.defaultFormat.backgroundColor.blue");
    propertiesDefaultFormatPaddingTop = CkJsonObject_IntOf(json,"properties.defaultFormat.padding.top");
    propertiesDefaultFormatPaddingRight = CkJsonObject_IntOf(json,"properties.defaultFormat.padding.right");
    propertiesDefaultFormatPaddingBottom = CkJsonObject_IntOf(json,"properties.defaultFormat.padding.bottom");
    propertiesDefaultFormatPaddingLeft = CkJsonObject_IntOf(json,"properties.defaultFormat.padding.left");
    propertiesDefaultFormatVerticalAlignment = CkJsonObject_stringOf(json,"properties.defaultFormat.verticalAlignment");
    propertiesDefaultFormatWrapStrategy = CkJsonObject_stringOf(json,"properties.defaultFormat.wrapStrategy");
    propertiesDefaultFormatTextFormatFontFamily = CkJsonObject_stringOf(json,"properties.defaultFormat.textFormat.fontFamily");
    propertiesDefaultFormatTextFormatFontSize = CkJsonObject_IntOf(json,"properties.defaultFormat.textFormat.fontSize");
    propertiesDefaultFormatTextFormatBold = CkJsonObject_BoolOf(json,"properties.defaultFormat.textFormat.bold");
    propertiesDefaultFormatTextFormatItalic = CkJsonObject_BoolOf(json,"properties.defaultFormat.textFormat.italic");
    propertiesDefaultFormatTextFormatStrikethrough = CkJsonObject_BoolOf(json,"properties.defaultFormat.textFormat.strikethrough");
    propertiesDefaultFormatTextFormatUnderline = CkJsonObject_BoolOf(json,"properties.defaultFormat.textFormat.underline");
    spreadsheetUrl = CkJsonObject_stringOf(json,"spreadsheetUrl");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"sheets");
    while ((i < count_i)) {
        CkJsonObject_putI(json,i);
        propertiesSheetId = CkJsonObject_IntOf(json,"sheets[i].properties.sheetId");
        propertiesTitle = CkJsonObject_stringOf(json,"sheets[i].properties.title");
        propertiesIndex = CkJsonObject_IntOf(json,"sheets[i].properties.index");
        propertiesSheetType = CkJsonObject_stringOf(json,"sheets[i].properties.sheetType");
        propertiesGridPropertiesRowCount = CkJsonObject_IntOf(json,"sheets[i].properties.gridProperties.rowCount");
        propertiesGridPropertiesColumnCount = CkJsonObject_IntOf(json,"sheets[i].properties.gridProperties.columnCount");
        i = i + 1;
    }



    CkJsonObject_Dispose(jsonToken);
    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);

    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.