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

Objective-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

 

 

 

(Objective-C) Google Sheets - Create a New Spreadsheet

Demonstrates how to create a new and empty spreadsheet.

Chilkat Objective-C Library Downloads

MAC OS X (Cocoa) Libs

iOS Libs

#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <NSString.h>

// 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..
CkoJsonObject *jsonToken = [[CkoJsonObject alloc] init];
BOOL success = [jsonToken LoadFile: @"qa_data/tokens/googleSheets.json"];
if ([jsonToken HasMember: @"access_token"] == NO) {
    NSLog(@"%@",@"No access token found.");
    return;
}

CkoHttp *http = [[CkoHttp alloc] init];
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:
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"sheets[0].properties.title" value: @"Sample Tab"];
[json UpdateString: @"properties.title" value: @"Create Spreadsheet using Sheets API v4"];

// Send the POST to create the new Google spreadsheet.
CkoHttpResponse *resp = [http PostJson3: @"https://sheets.googleapis.com/v4/spreadsheets" contentType: @"application/json" json: json];
if (http.LastMethodSuccess != YES) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%@%d",@"response status code = ",[resp.StatusCode intValue]);
NSLog(@"%@",@"response JSON:");

[json Load: resp.BodyStr];
json.EmitCompact = NO;
NSLog(@"%@",[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"
// }
// 

int i;
int count_i;

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

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