Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Google Sheets - Create a New SpreadsheetDemonstrates how to create a new and empty spreadsheet.
#include <CkJsonObject.h> #include <CkHttp.h> #include <CkHttpResponse.h> void ChilkatSample(void) { CkString strOut; // 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.. CkJsonObject jsonToken; bool success = jsonToken.LoadFile("qa_data/tokens/googleSheets.json"); if (jsonToken.HasMember("access_token") == false) { strOut.append("No access token found."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkHttp http; http.put_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: CkJsonObject json; 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. CkHttpResponse *resp = http.PostJson3("https://sheets.googleapis.com/v4/spreadsheets","application/json",json); if (http.get_LastMethodSuccess() != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("response status code = "); strOut.appendInt(resp->get_StatusCode()); strOut.append("\r\n"); strOut.append("response JSON:"); strOut.append("\r\n"); json.Load(resp->bodyStr()); json.put_EmitCompact(false); strOut.append(json.emit()); strOut.append("\r\n"); delete 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" // } // int i; int count_i; const char *spreadsheetId = json.stringOf("spreadsheetId"); const char *propertiesTitle = json.stringOf("properties.title"); const char *propertiesLocale = json.stringOf("properties.locale"); const char *propertiesAutoRecalc = json.stringOf("properties.autoRecalc"); const char *propertiesTimeZone = json.stringOf("properties.timeZone"); int propertiesDefaultFormatBackgroundColorRed = json.IntOf("properties.defaultFormat.backgroundColor.red"); int propertiesDefaultFormatBackgroundColorGreen = json.IntOf("properties.defaultFormat.backgroundColor.green"); int propertiesDefaultFormatBackgroundColorBlue = json.IntOf("properties.defaultFormat.backgroundColor.blue"); int propertiesDefaultFormatPaddingTop = json.IntOf("properties.defaultFormat.padding.top"); int propertiesDefaultFormatPaddingRight = json.IntOf("properties.defaultFormat.padding.right"); int propertiesDefaultFormatPaddingBottom = json.IntOf("properties.defaultFormat.padding.bottom"); int propertiesDefaultFormatPaddingLeft = json.IntOf("properties.defaultFormat.padding.left"); const char *propertiesDefaultFormatVerticalAlignment = json.stringOf("properties.defaultFormat.verticalAlignment"); const char *propertiesDefaultFormatWrapStrategy = json.stringOf("properties.defaultFormat.wrapStrategy"); const char *propertiesDefaultFormatTextFormatFontFamily = json.stringOf("properties.defaultFormat.textFormat.fontFamily"); int propertiesDefaultFormatTextFormatFontSize = json.IntOf("properties.defaultFormat.textFormat.fontSize"); 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"); const char *spreadsheetUrl = json.stringOf("spreadsheetUrl"); i = 0; count_i = json.SizeOfArray("sheets"); while ((i < count_i)) { json.put_I(i); int propertiesSheetId = json.IntOf("sheets[i].properties.sheetId"); propertiesTitle = json.stringOf("sheets[i].properties.title"); int propertiesIndex = json.IntOf("sheets[i].properties.index"); const char *propertiesSheetType = json.stringOf("sheets[i].properties.sheetType"); int propertiesGridPropertiesRowCount = json.IntOf("sheets[i].properties.gridProperties.rowCount"); int propertiesGridPropertiesColumnCount = json.IntOf("sheets[i].properties.gridProperties.columnCount"); i = i + 1; } SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.