How to Connect to & Open CSV Data in Microsoft Excel
The CData ODBC driver for CSV uses the standard ODBC interface to link CSV data with applications like Microsoft Access and Excel. Follow the steps below to use Microsoft Query to import CSV data into a spreadsheet and provide values to a parameterized query from cells in a spreadsheet.
If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.
Connecting to Local or Cloud-Stored (Box, Google Drive, Amazon S3, SharePoint) CSV Files
CData Drivers let you work with CSV files stored locally and stored in cloud storage services like Box, Amazon S3, Google Drive, or SharePoint, right where they are.
Setting connection properties for local files
Set the URI property to local folder path.
Setting connection properties for files stored in Amazon S3
To connect to CSV file(s) within Amazon S3, set the URI property to the URI of the Bucket and Folder where the intended CSV files exist. In addition, at least set these properties:
- AWSAccessKey: AWS Access Key (username)
- AWSSecretKey: AWS Secret Key
Setting connection properties for files stored in Box
To connect to CSV file(s) within Box, set the URI property to the URI of the folder that includes the intended CSV file(s). Use the OAuth authentication method to connect to Box.
Dropbox
To connect to CSV file(s) within Dropbox, set the URI proprerty to the URI of the folder that includes the intended CSV file(s). Use the OAuth authentication method to connect to Dropbox. Either User Account or Service Account can be used to authenticate.
SharePoint Online (SOAP)
To connect to CSV file(s) within SharePoint with SOAP Schema, set the URI proprerty to the URI of the document library that includes the intended CSV file. Set User, Password, and StorageBaseURL.
SharePoint Online REST
To connect to CSV file(s) within SharePoint with REST Schema, set the URI proprerty to the URI of the document library that includes the intended CSV file. StorageBaseURL is optional. If not set, the driver will use the root drive. OAuth is used to authenticate.
Google Drive
To connect to CSV file(s) within Google Drive, set the URI property to the URI of the folder that includes the intended CSV file(s). Use the OAuth authentication method to connect and set InitiateOAuth to GETANDREFRESH.
You can then work with live CSV data in Excel.
NOTE: In recent versions of Excel, Microsoft Query is not visible by default. To enable visibility, Navigate to Options > Data and check From Microsoft Query (Legacy) under the Show legacy data import wizards section.
- In Excel, open the Data tab and choose Get Data -> Legacy Wizards -> From Microsoft Query (Legacy).
- Choose the CSV DSN. Select the option to use Query Wizard to create/edit queries.
- In the Query Wizard, expand the node for the table you would like to import into your spreadsheet. Select the columns you want to import and click the arrow to add them to your query. Alternatively, select the table name to add all columns for that table.
- The Filter Data page allows you to specify criteria. For example, you can limit results by setting a date range.
- If you want to use parameters in your query, select the option to edit the query in Microsoft Query.
To set a parameter in the query, you will need to modify the SQL statement directly. To do this, click the SQL button in the Query Editor. If you set filter criteria earlier, you should have a WHERE clause already in the query.
To use a parameter, use a "?" character as the wildcard character for a field's value in the WHERE clause. For example, if you are importing the Customer, you can set "FirstName=?".
- Close the SQL dialog when you are finished editing the SQL statement. You will be prompted to enter a parameter value. In the next step, you will select a cell to provide this value. So, leave the box in the dialog blank.
-
Click File -> Return Data to Microsoft Excel. The Import Data dialog is displayed. Enter a cell where results should be imported.
- Close the Import Data dialog. You will be prompted to enter a parameter value. Click the button next to the parameter box to select a cell. Select the option to automatically refresh the spreadsheet when the value changes.