#31 - Write The First Lines of Multiples CSV Files to Excel

#31 - Write The First Lines of Multiples CSV Files to Excel

Problem description & analysis:

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

stock_301500.csvstock_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.65CODE,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.

ABCD
1CODEDTOPCL
23015002023-06-027167.8
33206882023-06-023332

Solution:

Write the following code in SPL IDE:

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

Explanation:

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.

For more references⬇️

SPL download address: esProc Desktop Download

Plugin Installation Method: SPL XLL Installation and Configuration

References to other rich Excel operation cases: Desktop and Excel Data Processing Cases

SPL Programming (YouTube FREE courses): https://www.youtube.com/playlist?list=PLQeR-IhHo7qNCw6o7PW8YfHvRx8pgzZso