VOOZH about

URL: https://www.cdata.com/kb/tech/xml-excel-cdataquery.rst

⇱ Excel Spreadsheet Automation on XML Data with the QUERY Formula


Excel Spreadsheet Automation on XML Data with the QUERY Formula

👁 Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Pull data from XML, automate spreadsheets, and more with the QUERY formula.

The CData Excel Add-In for XML provides formulas that can edit, save, and delete XML data. The following three steps show how you can automate the following task: Search XML data for a user-specified value and then organize the results into an Excel spreadsheet.

The syntax of the CDATAQUERY formula is the following:

=CDATAQUERY(Query, [Connection], [Parameters], [ResultLocation]);

This formula requires three inputs:

  • Query: The declaration of the XML data records you want to retrieve or the modifications to be made, written in standard SQL.
  • Connection: Either the connection name, such as XMLConnection1, or a connection string. The connection string consists of the required properties for connecting to XML data, separated by semicolons.

    Connecting to Local or Cloud-Stored (Box, Google Drive, Amazon S3, SharePoint) XML Files

    CData Drivers let you work with XML 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 XML file(s) within Amazon S3, set the URI property to the URI of the Bucket and Folder where the intended XML 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 XML file(s) within Box, set the URI property to the URI of the folder that includes the intended XML file(s). Use the OAuth authentication method to connect to Box.

    Dropbox

    To connect to XML file(s) within Dropbox, set the URI proprerty to the URI of the folder that includes the intended XML 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 XML file(s) within SharePoint with SOAP Schema, set the URI proprerty to the URI of the document library that includes the intended XML file. Set User, Password, and StorageBaseURL.

    SharePoint Online REST

    To connect to XML file(s) within SharePoint with REST Schema, set the URI proprerty to the URI of the document library that includes the intended XML file. StorageBaseURL is optional. If not set, the driver will use the root drive. OAuth is used to authenticate.

    Google Drive

    To connect to XML file(s) within Google Drive, set the URI property to the URI of the folder that includes the intended XML file(s). Use the OAuth authentication method to connect and set InitiateOAuth to GETANDREFRESH.

    The property is the controlling property over how your data is represented into tables and toggles the following basic configurations.

    • Document (default): Model a top-level, document view of your XML data. The data provider returns nested elements as aggregates of data.
    • FlattenedDocuments: Implicitly join nested documents and their parents into a single table.
    • Relational: Return individual, related tables from hierarchical data. The tables contain a primary key and a foreign key that links to the parent document.

    See the Modeling XML Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.

  • ResultLocation: The cell that the output of results should start from.

Pass Spreadsheet Cells as Inputs to the Query

The procedure below results in a spreadsheet that organizes all the formula inputs in the first column.

  1. Define cells for the formula inputs. In addition to the connection inputs, add another input to define a criterion for a filter to be used to search XML data, such as [ personal.name.last ].
  2. In another cell, write the formula, referencing the cell values from the user input cells defined above. Single quotes are used to enclose values such as addresses that may contain spaces.
  3. =CDATAQUERY("SELECT * FROM people WHERE [ personal.name.last ] = '"&B3&"'","URI="&B1&";DataModel="&B2&";Provider=XML",B4)
    👁 Formula inputs used in this example. (Google Apps is shown.)
  4. Change the filter to change the data. 👁 The outputs of the formula. (Google Apps is shown.)

Ready to get started?

Download a free trial of the Excel Add-In for XML to get started:

 Download Now

Learn more:

👁 XML Documents Icon
Excel Add-In for XML

The XML Excel Add-In is a powerful tool that allows you to connect with XML data stores directly from Microsoft Excel.

Use Excel to search, aggregate, read, write, and update XML documents directly. Perfect for mass imports / exports / updates, data cleansing & de-duplication, Excel based data analysis, and more!