You can create data sources to expose data in Microsoft Excel 97-2007 as services using the WSO2 Data Services Server. For demonstration, we use an excel sheet containing three columns, namely, ID, Model and Classification. The sheet is then filled with mock data. Note that the column names should appear in separate cells. For example,
To create a data source with Excel, first follow the steps in Creating Data Sources. When you select EXCEL as the data source type at the time a data source is created, the Excel-specific options appear. For example:
The Use Query Mode option in the UI allows you to create Excel data sources in two different ways as follows:
- Excel Data Sources in Non-Query Mode : Allows to directly expose the content of an Excel sheet as a service
- Excel Data Sources in Query Mode : Allows to query an Excel sheet in a familiar, SQL-like manner, and expose the results set as a service
Excel Data Sources in Non-Query Mode
After creating the data source in non-query mode, click Next to add a query. Note that the UI does not provide support to write a query. You can simply add Output Mappings to define how the output looks like. For example,
Excel Data Sources in Query Mode
After creating the data source in query mode, click Next to add a query. Note that the UI provides support to write a query. For example,
Internally, the class org.wso2.carbon.dataservices.sql.driver.TDriver
is used as the SQL Driver. It is a JDBC driver implementation used with tabular data models such as Google Spread Sheets, Excel sheets etc.
At the moment, the query mode supports only basic SELECT, INSERT, UPDATE and DELETE queries. Nested queries will be supported in an upcoming release. Given below are the supported queries with examples:
Queries supported in the query mode
Sample 1:
SELECT customerNumber, customerName, phone, state, country FROM customers
Sample 2:
INSERT INTO customers (customerNumber, customerName, contactLastName) VALUES(?,?,?)
Sample 3:
UPDATE customers SET contactFirstName=?, contactLastName=? WHERE customerNumber=?
Sample 4:
DELETE FROM customers WHERE customerNumber=?
You can also create new sheets in the Excel or drop existing sheets.
Sample 5:
CREATE SHEET ProductCategories (ProductCode, Category)
Sample 6:
DROP SHEET ProductCategories
Also, see a demonstration of service enabling an Excel sheets in Excel Sample.