Delphi以编程方式复制csv列

时间:2016-12-03 09:25:33

标签: delphi

我正在使用Delphi,我需要以编程方式复制列及其来自.csv文件的数据。

我需要做的确切任务:

1. Load the csv content (could be into a stringlist or other)
2. Copy column 4 (and it's data)
3. Add a new column on column 2's place and add this copied column
4. Save

这是Delphi可以做的吗?如果是这样,有人可以让我开始或指导如何做到这一点吗?

1 个答案:

答案 0 :(得分:0)

Create two stringlists `Data` and `Temp`
Load file into Data
For every line of Data:
    Assign this line to Temp.CommaText  
    (this assumes that line format doesn't violate CommaText rules, 
     otherwise do partition by hands or with dedicated CSV libraries)
    Insert Temp[3] before Temp[1]
    Assign CommaText back to Data line
Save Data
Free objects