Find the First and Last Data

Find locations

The data of the file book1.xlsx is shown in the figure below, in which the first row is the column name. Some cells in other rows are empty, some cells have data, and the cells with data must be continuous.

..

Now we need to calculate the column names of the starting and ending columns of the cells with continuous data in column A and column B respectively, as shown in the following figure:

..

Write SPL script:


A

1

=file("E:/work/book1.xlsx").xlsimport@w()

2

=A1.to(2,).run(~(1)=A1(1)(~.pselect(~)),~(2)=A1(1)(~.pselect@z(~)))

3

=file("E:/work/book2.xlsx").xlsexport@w(A1)

A1: Read in the data of the employee information table, and the @w option means to read the data as a sequence of sequences

 

A2 Loop through each row starting from Row 2 of A1, find sequence number of the first non-null member, get the member at this sequence number in Row 1 of A1, and assign the value to the first member of the current row; find sequence number of the last non-null member, get the member at this sequence number in Row 1 of A1 and assign it to the second member of the current row. The @z option means to find data from back to front.

 

A4 Store A1 to the file book2.xlsx, and the @w option indicates that the object A1 to be exported is a sequence of sequences

 

Find members

Some data of the stock quote table stock.xlsx are shown in the figure below:

..

Please find out the records of the first time and the last time that the closing price of stock 600027 is higher than 10 yuan respectively.

Write SPL script:


A

1

=T("E:/work/stock.xlsx")

2

=A1.select@1(Code=="600027"   && Close>10)

3

=A1.select@z1(Code=="600027"   && Close>10)

 

A1 Read in the stock quote data

 

A2 Select the record where the closing price of stock 600027 is higher than 10 yuan for the first time, and the @1 option means to select the first record that meets the condition

 

A3 Select the record where the closing price of the stock 600027 is higher than 10 yuan for the last time, and the @z option means to find the record from back to front