Lesson 2 - Sending HTTP Requests

This document is the second step of the Getting Started tutorial, and describes how to work with the SpreadsheetCloudAPI service from your application using HTTP protocol. For detailed instructions on how to "bind" your application to the server, refer to Lesson 1.

First of all, let's upload a file to the application created in Lesson 1 using the file manager on the right of the SpreadsheetCloudAPI web interface. For this purpose, click Upload and select an existing file using the Open File dialog. The supported file extensions are: OPENXML (XLSX), XLS and CSV.

Note

The maximum file size is limited by 10MB. The maximum storage size (all files for all applications per one account) is limited by 100 MB.

As an alternative, click Create empty file, specify required file credentials (name and extension) and click Create in the subsequent dialog. The created file will be added to the currently-selected application.

Now, we can work with this file through HTTP protocol. Below is a list of basic tasks and corresponding requests that are used to realize these tasks.

Note

All of the sent requests must be authorized by the application's API Key. For more information on authorizing requests, refer to the Authorization document.

  1. Specify the base URL for sent requests. For example, you can use the following code.

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("http://spreadsheetcloud.azurewebsites.net");
  2. Load a document into a new SpreadsheetCloudAPI service's session. The output response returns the session identifier (id). Use this identifier in further requests to access the corresponding document.

    GET /api/spreadsheet/loaddocument?filename=myapplicationfile&extension=xlsx

    Output example:

    {
    "id": "some_id",
    "filename": "myapplicationfile",
    "extension": "xlsx"
    }
  3. Get a list of worksheets belonging to the document.

    GET /api/spreadsheet/getworksheets?id=some_id

    Output example:

    [Sheet1, Sheet2 ...]
  4. Set a cell value.

    PUT /api/spreadsheet/setcellvalue

    Input example:

    {
    "id": "some_id",
    "sheetindex": 0,
    "sheetname": "Sheet1",
    "rowindex": 0,
    "columnindex": 0,
    "value": 5
    }

    Output example:

    {
    "id": "some_id",
    "sheetindex": 0,
    "sheetname": "Sheet1",
    "rowindex": 0,
    "columnindex": 0,
    "value": 5
    }
  5. Add a formula to a cell.

    PUT /api/spreadsheet/setformula

    Input example:

    {
    "id": "some_id",
    "sheetindex": 0,
    "sheetname": "Sheet1",
    "rowindex": 1,
    "columnindex": 0,
    "value": "=A1*B1"
    }

    Output example:

    {
    "id": "some_id",
    "sheetindex": 0,
    "sheetname": "Sheet1",
    "rowindex": 1,
    "columnindex": 0,
    "value": "=A1*B1"
    }
  6. Get a cell value.

    GET /api/spreadsheet/getcellvalue?id=some_id&sheetindex=0&sheetname=Sheet1&rowindex=1&columnindex=0

    Output example:

    {
    "id": "some_id",
    "sheetindex": 0,
    "sheetname": "Sheet1",
    "rowindex": 1,
    "columnindex": 0,
    "value": 50
    }
  7. Close and save the document.

    GET /api/spreadsheet/closedocument?id=some_id&filename=myapplicationfile&extension=xlsx&savechanges=true

For more information on supported HTTP requests, see the Protocol API Reference section.