?
Solved

Problem with CSV File

Posted on 2007-10-01
15
Medium Priority
?
370 Views
Last Modified: 2010-04-05
Hi all,

I have a problem with a CSV file with I need to sort from my application.

These are the steps in what I need the program to do:

1. Read a CSV File
2. Sort the CSV by .... (This could be different, so I just need to be able to sort the CSV)
3. Save it back to Disk.

Hope you can help.

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 6
  • 5
  • 3
  • +1
15 Comments
 

Author Comment

by:ST3VO
ID: 19990924
By the way: The sorting would be perfect if I could use an SQL Query but I dont know if it can be done!

Thanks again!
 
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19991045
  Hi!

Here are some CSV examples : http://www.java2s.com/Code/Java/Development-Class/CSV-File.htm
Then for sorting just call Collections.Sort(l) as shown in this
example http://www.java2s.com/Code/Java/Collections-Data-Structure/Sortalist.htm
Here are so some OpenSource libraries to aid you in reading/writing CSV files.
http://opencsv.sourceforge.net/
http://supercsv.sourceforge.net/

Regards,
   Tomas Helgi
0
 

Author Comment

by:ST3VO
ID: 19991062
I need something in Delphi please!

All the samples point to JAVA Code.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19991094
Hmmm sorry about this confusion :)


Regards,
  Tomas Helgi
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19991133
   
JEDI Project has a component called JTvCustomDataSet  where you
can read CSV file into a TDataSet Descendant, do some sorting and
export it back to a CSV file.

Regards,
  Tomas Helgi
0
 
LVL 1

Expert Comment

by:kiranmahale
ID: 19991320
Use TstringList and use Loadfromfile(<filename>) method to load the into stringlist and then sort the TStringlist object. Once u sort Tstringlist use method called Savetofile to save it back with new sort
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19991366
Thats one way to do it. :)
However that will leed to the fact that you have to code sorting routines
for every different CSV file that the program will use in the future.
Using the DataSet descendants gives you more user-friendlier control
over sorting different CSV files.

Regards,
  Tomas Helgi
0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19991374
And of course handling the data. :)

Regards,
   Tomas Helgi
0
 

Author Comment

by:ST3VO
ID: 19991452
My problem is that I might have to use a database connection somehow as there will be sort SQL involved.

This is want I need to do:

1. Program Loads
2. <Code connects to the CSV file>
3. User performs a query (e.g: I'll have a couple of Combos 1.All Cars 2.Red Cars
4. Then the <code> will filter this and Sort the data so that the Query results are first
5. Save back to CSV.

Any ideas please?

Thanks again!


0
 
LVL 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 19991616
Use JTvCustomDataSet. That component is ideal for
this as you can use Filter to filter out the desired data
and save it back to CSV file easilly.

Regards,
  Tomas Helgi
0
 
LVL 17

Expert Comment

by:mokule
ID: 19991644
You can use ADO
0
 
LVL 17

Expert Comment

by:mokule
ID: 19991667
Any problems with it?
0
 

Author Comment

by:ST3VO
ID: 19991814
I've looked up some connection strings for csv using ADO but none of them work so I keep searching :o)
0
 
LVL 17

Accepted Solution

by:
mokule earned 2000 total points
ID: 19992918
Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=D:\Usr\Marek\Proj\test\testcsv\;Mode=Share Deny None;Extended Properties=text;Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=96;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False

This is working for csv.
Change only Data Source= for Your needs to point to folder with Your csv files
0
 

Author Comment

by:ST3VO
ID: 19992961
Great! Works perfect! Thanks :o)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question