How Reporting Tools Access TXT/CSV/XLS Data

Reporting tools generally support file sources, such as txt/csv/xls. Yet they only provide basic computing abilities for computing files with regular formats. They need to find indirect ways to handle complicated computing tasks or files with irregular formats. A popular solution is to use the user-defined data set plus the third-party class library. There are various file handling class libraries. They have strong parsing abilities but weak computing abilities. A lot of hard coding work is needed to achieve computing tasks. Another way is to execute SQL directly on files using CSVJDBC/XLSJDBC. The solution is integration-friendly and easy to learn, but it has weak parsing and computing abilities, does not have date functions and string functions, and provides no support of join operations, set-oriented operations and subqueries.

The wise choice is to use SPL. The Java-based, open-source class library offers powerful computational capabilities, is able to parse files with irregular formats, and has JDBC interface that is easy to integrated by reporting tools.

SPL provides analytic functions of simplistic syntax. The library can use one T function to parse regular files of various formats:

T("d:/Orders.csv")                    // Comma-separated and the first row contains column names
T("d:/Employees.txt)                // Tab-separated and the first row contains column names
T("d:/data.xls")                       // The row-wise xls/xlsx and the first row contains column names

SPL has a wealth of built-in functions for processing file data using simple and intuitive syntax, without the need of any complicated hardcoding. To perform a query on orders data according to interval-style conditions, for instance, we have the following SPL code, where p_start and p_end are parameters:





select(Amount>p_start && Amount<=p_end)=A1.


return A2

As code written in an RDB, SPL code can be integrated into a reporting tool through its JDBC driver. Take the above SPL code as an example, we can first save it as a script file (intervalQuery.splx) and then invoke it in the reporting tool as we do with a stored procedure. Suppose we are using Birt and the code is as follows:

{call intervalQuery(? , ?)}

More examples:




2>1000 && like(Client,\"*S*\"))

//Fuzzy query





=A1 .id(Client)




//Grouping & aggregation


=join(A1:O,SellerId; T("D:/Employees.txt"):E,EId).new(O.OrderID, O.Client,O.Amount,E.Name,E.Gender,E.Dept)



It is easy for SPL to handle files of irregular formats:

To parse a CSV file using the special double horizontal line as the separator:

= file("D:/Orders.txt").import@t(;,"--").select(Amount>1000 && Amount<=3000)

In the file, every three lines forms one record, and the second line contains multiple fields. We are trying to reorganize the file into a standard two-dimensional table sorted by the 3rd and the 4th fields:





3,(line=~(2).array("\t"))(1):Client,line(2):SellerId,line(3):Amount,~(3):OrderDate )




It is simple for SPL to handle XLS files of irregular formats. Here are some common examples:

// To import a file without column names where detail data begins from the first row:

// To import a file by skipping the title area in the second row:

// To import rows from the 3rd to the 10th:

// To import only three columns:

// To import data from the specified “sheet3”:

The xlsimport function can also import N rows backward, open a big file using a password, and read data from a big file. We just skip the detailed explanations about them here.


SPL also supports standard SQL syntax, including plenty of string functions and date functions, join operations, set-oriented operations and subqueries. To accomplish the above query based on interval-style conditions, we can create a SQL data set in the reporting tool and write the following SQL statement:

$select * from d:/Orders.csv where Amount>? and Amount<=?

To perform a join:

$select, s.orderdate, s.amount from sales.xls  s left join employee.csv e on s.sellerid= e.eid

More examples can be found in Examples of SQL Queries on Files.


SPL possesses outstanding computational capabilities to simplify computations with complex logic, including stepwise computations, order-based computations and post-grouping computations. SPL can deal with many computations effortlessly that are hard to handle in SQL. Here is an example. We are trying to find the first n big customers whose sales amount occupies at least half of the total and sort them by amount in descending order.




 / Retrieve data



/ Sort data by amount in descending order



/ Get the sequence of cumulative totals



/ The last cumulative total is the final total



/ Get position of record where the cumulative total reaches at least half of the total



/ Get values by position

In the following Excel sheet, every 8 rows constitute one record whose fields are scattered among different cells. We are trying to retrieve records one by one and generate a standard two-dimensional table.

This is a complicated, multi-step task that involves loop control and order-based computation. For class libraries like POI, it is a heavy project while for SPL, it is simple and easy. Below is the short SPL code:















if len(B4(1))==0







SPL has a professional IDE equipped with all-around debugging functionalities and lets users observe the result of each step with grid-style coding, making it particularly suited to developing algorithms with complex logic.


SPL also supports many more data sources, including WebService, RESTful, MongoDB, Hadoop, Redis, ElasticSearch, SalesForce, and Cassandra, and the mixed computations between any types of data sources or databases.


esProc SPL Source Code and Package 👉

esProc SPL Official Website 👉

esProc SPL Forum 👉