Subject Re: csv import into dbf
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Sat, 17 Aug 2024 19:24:03 +0530
Newsgroups dbase.getting-started

Good Evening Charlie,

> I would like to allow the user to import a csv file with headers I suppose or in a certain order, into my table.  I know how to export to csv from a table, but am not sure how to start with import.  Any ideas or suggestions?  Thanks

The code I use

local csv_file
csv_file = getfile("*.csv")
if empty(csv_file)
          //do nothing
else
             use import_purch exclusive
**************
             zap
             in_file = new file()
             in_file.open(csv_file,"R")
             //Remove the header line +1 linve
             mline = in_file.readln()
             mline = in_file.readln()
             out_file = new file()
             out_file.create("import_p.csv")
             do while not in_file.eof()
                //Write rest of the lines
                out_file.puts(in_file.readln())
             enddo
             //End remove header line
             in_file.close()
             out_file.close()
****************
             append from "import_p.csv" delimited
             use
endif

In the above example I have removed 2 lines.

If you are not removing the header section then the entire code between
the astrix line is not required.
Regards
Akshat