This tutorial will guide you on how to expose data in an Excel sheet as a data service by using the Create New Data Service wizard. We will create a data service that can search for data on the file and insert data into the file.
Note |
---|
WSO2 EI uses the Apache POI library version 3.9.0 to work with Excel datasources, and thereby, supports both XLS and XLSX formats. For more information, go to Apache POI Documentation. |
To demonstrate this feature, we will use the Products.xls
file that is shipped with WSO2 EI by default. The Products.xls
file is stored in the <EI_HOME>/samples/data-services/resources/
folder and it contains data about products ( cars/motorcyles) that are manufactured in an automobile company. The data table has the following columns: "ID", "Model" and "Classification".
...
- Click Add New Query to open the Add New Query screen.
- Enter Q1 as the query id in the Query ID field.
In the Datasource field, select the datasource for which you are going to write a query. Select the Excel datasource that you created previously.
- You can directly specify the details of the spreadsheet as shown below.
- Define Output Mapping: Now, let's specify how the data fetched from the datasource should be displayed in the output. The sample Excel datasource we are using contains three columns: ID, Model and Classification. We will create an output mapping for each of these columns.
- In the Output type field, specify the format in which the query results should be presented. You can select XML, JSON or RDF. We will use XML for this tutorial.
- In the Grouped by element field, specify a grouping for all the output mappings. This will be the XML element that will group the query result. Enter Products in this field.
- In the Row Name field, specify the XML element that should group each individual result. Enter Product in this field.
- Click Add New Output Mapping to start creating the output mapping for the ID column. Enter values as shown below:
- Click Add to save the output mapping.
Create output mappings for the remaining columns given below.
Mapping Type Element Name Datasource Type Datasource Column Name Parameter Type Schema Type Element Model Column Model SCALAR string Element Classification Column Classification SCALAR string Info Find out more about defining Output Mappings.
- Click Next to go to the Operations screen.
...