Forum > Databases

Tools for manage CSV files

<< < (2/3) > >>

Root2:
Hi AlexTP, thanks for replying, basically what I am looking for is in a CSV file that is delimited by (,) to convert its rows to columns, I can not do it manually as this CSV is received from a PLC and once received the data must be loaded automatically to a DB.

Thank you.

Root2:
Egsuh thanks for the answer, I think the solution is to join the CSV files in one, my main problem is that the CSV files are coming to me in rows, so it does not meet the structure of the DB, in order to insert the data correctly I must convert the CSV data to columns.

data1,data2,data3...

convert to.

data1
data2
data3
.
.

Thank you very much for your attention.

Zvoni:
You're contradicting yourself.

--- Quote ---each CSV file has DATE, TIME, DATA, INGREDIENT data
--- End quote ---
You say, that the CSV has 4 columns, but you only show one ("Data")
What now?
Are you getting each "needed" column in its own CSV, and there as a single row instead of columns?
Post an example of the CSV contents.
Sounds simple enough

SymbolicFrank:
A TStringList has a Delimiter and a DelimitedText. If you set the Delimiter to ',' and assign the CSV file to it:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  csv, l: TStringList;begin  csv := TStringList.Create;  csv.LoadFromFile('yourcsvfile.csv');  l := TStringList.Create;  l.Delimiter := ',';  l.DelimitedText := csv.Text;  // now all of them have their own entry in l.  l.Free;  csv.Free;end;
And you can use a third TStringList to assemble your new file:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  AllOfThem := TStringList.Create;  for i := 0 to l.Count - 1 do AllOfThem[i] := AllOfThem[i] + ';' + l[i];
But you should insert the first file directly into AllOfThem and only add all the others like that.

Zvoni:
A StringList is IMO overkill for a simple string delimited with commas.
Just split it.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version