Ready to get started?

Learn more about the CData Excel Add-In for Cosmos DB or download a free trial:

Download Now

Transfer Data from Excel to Cosmos DB

This article explains how to transfer data from Excel to Cosmos DB using the Excel Add-In for Cosmos DB.

The CData Excel Add-In for Cosmos DB enables you to edit and save Cosmos DB data directly from Excel. This article explains how to transfer data from Excel to Cosmos DB. This technique is useful if you want to work on Cosmos DB data in Excel and update changes, or if you have a whole spreadsheet you want to import into Cosmos DB. In this example, you will use the Customers table; however, the same process will work for any table that can be retrieved by the CData Excel Add-In.

Establish a Connection

If you have not already done so, create a new Cosmos DB connection by clicking From Cosmos DB on the ribbon.

To obtain the connection string needed to connect to a Cosmos DB account using the SQL API, log in to the Azure Portal, select Azure Cosmos DB, and select your account. In the Settings section, click Connection String and set the following values:

  • AccountEndpoint: The Cosmos DB account URL from the Keys blade of the Cosmos DB account
  • AccountKey: In the Azure portal, navigate to the Cosmos DB service and select your Azure Cosmos DB account. From the resource menu, go to the Keys page. Find the PRIMARY KEY value and set AccountKey to this value.

Retrieve Data from Cosmos DB

To insert data into Cosmos DB, you will first need to retrieve data from the Cosmos DB table you want to add to. This links the Excel spreadsheet to the Cosmos DB table selected: After you retrieve data, any changes you make to the data are highlighted in red.

  1. Click the From Cosmos DB button on the CData ribbon. The Data Selection wizard is displayed.
  2. In the Table or View menu, select the Customers table.
  3. In the Maximum Rows menu, select the number of rows you want to retrieve. If you want to insert rows, you need to retrieve only one row. The Query box will then display the SQL query that corresponds to your request.
  4. In the Sheet Name box, enter the name for the sheet that will be populated. By default the add-in will create a new sheet with the name of the table.

Insert Rows to Cosmos DB

After retrieving data, you can add data from an existing spreadsheet in Excel.

  1. In a cell after the last row, enter a formula referencing the corresponding cell from the other spreadsheet; for example, =MyCustomersSheetInExcel!A1.
  2. After using a formula to reference the cells you want to add to Cosmos DB, select the cells that you are inserting data into and drag the formula down as far as needed. The referenced values you want to add will be displayed on the Customers sheet.
  3. Highlight the rows you want to insert and click the Insert Rows button.

As each row is inserted, the Id value will appear in the Id column and the row's text will change to black, indicating that the record has been inserted.