[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

URGENT!!! Export to CSV file using Delphi 7

Posted on 2004-10-26
8
Medium Priority
?
1,507 Views
Last Modified: 2010-04-05
Hi experts!

I need to export my oracle data to a csv file. How do I do that? I can import the data but I don't know how to export it. I know it should be the opposite way to do it but how?

 if OpenDialog.Execute then
    begin
      //read the CSV file into a text string
      if FileExists(OpenDialog.FileName) then
      begin

        AssignFile(CSVFile, OpenDialog.FileName);
        Reset(CSVFile);

        CSVClassFileOutLine := TStringList.Create;
        //read line by line while not end of file
        CSVFileOutLine.Delimiter := ',';
        CSVFileOutLine.QuoteChar := '"';

        while not EOF(CSVFile) do
        begin
          Readln(CSVFile, CSVFileLine);
          CSVFileOutLine.DelimitedText := CSVFileLine;

        end;//end while
      end; //file exists

      CSVFileOutLine.Free;
      CloseFile(CSVFile);
    end;
end;
0
Comment
Question by:rodneylim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Expert Comment

by:SaLz
ID: 12414529
have a try of this.

procedure TForm1.Button1Click(Sender: TObject);
var F:TextFile;
    i : integer;
begin
 AssignFile(F, 'c:\griddata.csv');
 Rewrite(F);
 for i := 0 to stringgrid1.RowCount-1 do
 begin
  writeln(F,stringgrid1.Rows[i].CommaText);
 end;
 CloseFile(F);
end;


this is from http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10300557.html

Sal.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12414773
You need to export your Oracle data and you're showing us how you import the CSV file. But in the while-loop you continuously replace the contents of CSVFileOutLine. By assigning a value to DelimitedText, you just repeatedly change the contents. I fear you're confusing things a little here...
0
 
LVL 2

Expert Comment

by:SaLz
ID: 12414858
he said he already imported the data from the oracle to his program, he wants 2 export it, if am wrong then am sorry, bgz on me. I do apologize.

Sal.
0
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.

 
LVL 2

Expert Comment

by:SaLz
ID: 12415009
ye, hes showing us his way of importing of his csv, and he wants 2 export data from his oracle database, I was wondering the same thing, it was little confusing, but his question title was sound, export 2 csv in delphi 7.

u probly will have 2 connect 2 ur db, then list the data into the grid, then export it that way.

Sal.
0
 

Author Comment

by:rodneylim
ID: 12418167
Hi guys!

What I showed was my import of my csv file to my oracle data. The loop is to write line by line into the oracle database. It is just to show what I have done on the import side. What I do not know is how to export the existing oracle database back into a csv file. It is just the opposite way of what I have done which I think I still have to use the while loop right?

Example of the CSV file when opened with a notepad.
133456, "Finance 100", "School of Business"

I hope I explained more clearly this time! Thanks guys!
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 375 total points
ID: 12418572
var
  s : string;
  i : integer;
begin  
  adoquery.sql.text := 'YourSelectYouHave';
  adoquery.open;
  AssignFile(CSVFile, SaveDialog.FileName);
  Rewrite(CSVFile);
  while not adoquery.eof do
  begin
    s := '';
    for i := 0 to adoquery.fields.count - 1 do
      if adoquery.fields[i].DataType = ftString then
         s := s+'"'+adoquery.fields[i].AsString+'",'
      else
         s := s+adoquery.fields[i].AsString+',';
    delete(s,length(s),1);  //delete last comma
    writeln(CSVFile,s);
    adoquery.next;
  end;
  adoquery.close;
  closefile(CSVFile);
end;

just from head

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12470517
hello?
0
 

Author Comment

by:rodneylim
ID: 12472912
sorry for the delay...it is been a hectic period for me! thanks for your help kretzschmar!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 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