2016-12-03 71 views
-6

我正在使用Delphi,我需要以編程方式複製一列,並且它是.csv文件中的數據。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 

這是不是德爾福可以做什麼?如果是這樣,任何人都可以讓我開始或指導如何做到這一點?

+1

找到自己的CSV解析庫。見例如這裏是一個商業的:http://www.winsoft.sk/csv.htm。或者,您可以從免費的JEDI庫中使用此數據集組件:http://wiki.delphi-jedi.org/wiki/JVCL_Help:TJvCsvDataSet – MartynA

+5

Delphi是一種編程語言。你是一名程序員。德爾福不能做到這一點。但是你可以。 –

+0

請顯示所進行研究的證據,您已實施的代碼以及您遇到的具體問題...請回顧[如何提問](http://stackoverflow.com/help/how-to-ask)和考慮提供[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve) – David

回答

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