June 17, 2024, 08:24:23 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


CSV Importer

Started by Brian, June 06, 2013, 07:10:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hello,
I've been attempting to create a universal CSV file importer, with some success. It does read
fields surrounded by quotes, quoted fields with commas inside, fields surrounded just by commas, etc

But . . . it doesn't always read the data correctly. Sometimes it falls short of the total number of lines
in the input file, sometimes it will put the same data in consecutive fields, sometimes it won't load
at all

Bit of a monster, and it's not playing fair! Someone with a higher intellect than mine (not hard)
may see something. Could you have a play, and suggest something (anything!) ?

Brian

PS: You will need Fletchie's ctl.lib

billhsln

How about 4 lines of sample data to test with?

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

Brian
I'm leaving to go out of town in about and hour and won't be back until tomorrow night.
I'll look at what you have when I get back.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Quote from: billhsln on June 06, 2013, 07:35:35 AM
How about 4 lines of sample data to test with?

Thanks,
Bill
preferably lines that are giving you problems
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Hi,
Save this text as "schema.ini" - change the [Filename] section to the name of the file
you are about to open, eg, [TestFile.csv] and see how that goes

I can now load all my test files with this method, although I am still getting duplicate
data in fields. Need to look at that, now

Doesn't seem to matter if you have too many field definitions (more than your source
csv file contains), although I suppose it would matter if you didn't have enough!

Brian

[Filename]
Format=CSVDelimited
CharacterSet=ANSI
Col1=Field1 Text
Col2=Field2 Text
Col3=Field3 Text
Col4=Field4 Text
Col5=Field5 Text
Col6=Field6 Text
Col7=Field7 Text
Col8=Field8 Text
Col9=Field9 Text
Col10=Field10 Text
Col11=Field11 Text
Col12=Field12 Text
Col13=Field13 Text
Col14=Field14 Text
Col15=Field15 Text
Col16=Field16 Text
Col17=Field17 Text
Col18=Field18 Text
Col19=Field19 Text
Col20=Field20 Text
Col21=Field21 Text
Col22=Field22 Text
Col23=Field23 Text
Col24=Field24 Text
Col25=Field25 Text
Col26=Field26 Text
Col27=Field27 Text
Col28=Field28 Text
Col29=Field29 Text
Col30=Field30 Text

billhsln

Here is my version that seems to work ok for me.  Test it out and let me know if it works ok for you.

Bill
When all else fails, get a bigger hammer.