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

Node.js Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Node.js) Google Sheets - Create a New Spreadsheet

Demonstrates how to create a new and empty spreadsheet.

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node11-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node11-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node11-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node11-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node11-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node11-macosx');
}

function chilkatExample() {

    // 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..
    var jsonToken = new chilkat.JsonObject();
    var success = jsonToken.LoadFile("qa_data/tokens/googleSheets.json");
    if (jsonToken.HasMember("access_token") == false) {
        console.log("No access token found.");
        return;
    }

    var http = new chilkat.Http();
    http.AuthToken = jsonToken.StringOf("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:
    var json = new chilkat.JsonObject();
    json.UpdateString("sheets[0].properties.title","Sample Tab");
    json.UpdateString("properties.title","Create Spreadsheet using Sheets API v4");

    // Send the POST to create the new Google spreadsheet.
    // resp: HttpResponse
    var resp = http.PostJson3("https://sheets.googleapis.com/v4/spreadsheets","application/json",json);
    if (http.LastMethodSuccess !== true) {
        console.log(http.LastErrorText);
        return;
    }

    console.log("response status code = " + resp.StatusCode);
    console.log("response JSON:");

    json.Load(resp.BodyStr);
    json.EmitCompact = false;
    console.log(json.Emit());

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

    var i;
    var count_i;

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


}

chilkatExample();

 

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