Write the first lines of multiple csv files to Excel

There are multiple csv files of same structure in a certain directory:

stock_301500.csv

stock_320688.csv

CODE,DT,OP,CL

301500,2023-06-02,71,67.8

301500,2023-06-05,79.35,72.61

301500,2023-06-06,75.8,77.65

CODE,DT,OP,CL

320688,2023-06-02,33,32

320688,2023-06-05,28.37,30.23

320688,2023-06-06,27.19,28.54

Task: Take the first line of each file (without column headers) and write them to an Excel file.


A

B

C

D

1

CODE

DT

OP

CL

2

301500

2023-06-02

71

67.8

3

320688

2023-06-02

33

32

Write the following code in SPL IDE:

=T("result.xlsx": directory@p("D:\\data\\*.csv").(T(~)(1)))

directory@p lists file names with full paths according to the wild character. T()function reads files or writes data to a file as a specified format according to the file extension; ~ is the current member, and (1) represents the first line.

Source:https://stackoverflow.com/questions/78222822/vba-to-copy-all-top-rows-from-files-in-the-same-folder-and-merge-into-1-file