Subject |
Re: csv import into dbf |
From |
Akshat Kapoor <akshat.kapoor@kapoorsons.in> |
Date |
Sun, 18 Aug 2024 14:36:30 +0530 |
Newsgroups |
dbase.getting-started |
Good Evening Mervyn,
>> 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
>
> Appending from a .csv file can be very simple or it can be fairly complex.
>
> dBASE has a built-in mechanism for appending from .csv files but it has
> severe limitations.
>
> use whatever.dbf
> append from whatever.csv delimited
> use
>
> The limitations are that dates in the .csv file must be in the format
> ...,yyyymmdd,... i.e no delimiter and no separator between year, month
> and day. It can't import into a memo field and it can't handle a .csv
> file that has field names in the first line. Basically, it can only
> deal with .csv files created using the dBASE command COPY TO
> whatever.csv DELIMITED
>
> Very few, if any, applications can handle, or create, .csv files that
> meet these criteria so I created append_from_csv.prg which is in the
> dUFLP. By setting various switches one should be able to import
> virtually any .csv file.
>
> As you have the field headers in your .csv file I assume you have used
> usv_out.prg from the dUFLP to create it with dates in "mm/dd/yyyy" format.
>
> If so,
>
> set procedure to :duflp:append_from_csv.prg
> append_from_csv('whatever.dbf',whatever.csv','a',true)
>
>
> should do the trick. As the switch to skip the first line is the 4th
> parameter the third parameter (the date setting) also need to be set.
>
> If it doesn't import correctly it means that there are other switches
> that need to be set. If you can't figure them out post the first data
> line in your .csv file.
I agree with you on most counts.
But it is not a thing that requires tooooo much coding if you opt in for
DIY route.
I have successfully imported from finger print attendance machine (the
format/end of line marker of txt file is unix. And the date format is
yyyy-mm-dd).
Using file object open the source file. Read lines make desired
alterations to the line and save it to a new file. That file is ready
for append from .......
I have successfully imported from bank statements downloaded in the
delimited format.
Open the source file. Using breakstring() of stringex.cc in duflp and
use the desired values to append rows into a table.
And this is not counting the import from a csv that I have created in excel.
Yes the coding has to be meticulous. You have to know the source
precisely but after that it is not that difficult
Regards
Akshat
|
|