Forums › Forums › SIMPOL Programming › How Impor a CSV file into table?
Tagged: Import CSV
- This topic has 4 replies, 3 voices, and was last updated 7 years, 1 month ago by Michael.
- AuthorPosts
- June 6, 2017 at 3:18 am #3505jesusbluesParticipant
Where can I find an example code to import a CSV file?
June 6, 2017 at 12:23 pm #3506JD KromkowskiParticipantUse “File>Import” in Personal
Or is the actual code important? I don’t think that it is currently available to public but probably uses fsfileinputstream
July 4, 2017 at 2:21 am #3529jesusbluesParticipantI need create a routine for import a CSV file and integrate this code in my program.
I nedd the code example.July 6, 2017 at 1:50 pm #3531JD KromkowskiParticipantThe code for dbconverter.sml doesn’t seem to be available. But if you add it to your project and take a look at dbCSVImport that might point you in right direction. I have no direct experience with this library.
Without the dbconverter library, I’d think you’d start reinventing the wheel with something like
fsfileinputstream f
f =@ fsfileinputstream.new(“c:\mycvs.cvs”)Otherwise, you might ask Neil directly.
July 20, 2017 at 5:05 pm #3534MichaelKeymasterThe following code demonstrates an import merge from CSV to SBME. It uses the dbconverter.sml, the address.sbm from the Address Book tutorial, and an address.csv containing 4 rows of data. Please note that there is no provision currently for assigning a value to a record ID type of field. Either the import data needs that information in the appropriate field, or some other mechanism would be required to assign the required information after the import is completed. Also, this example does not demonstrate how to use a field list to restrict or reorder the data to match the output/input. It assumes that every field is present and in the correct order in the import file.
Ciao, Neil
function main() sbme1 sbmfile sbme1table table integer e, rowsout string s e = 0 sbmfile =@ sbme1.new("address.sbm", "O", error=e) if sbmfile =@= .nul s = "Error " + .tostr(e, 10) + " opening database file address.sbm{d}{a}" else table =@ sbmfile.opentable("Address", error=e) if table =@= .nul s = "Error " + .tostr(e, 10) + " opening table Address{d}{a}" else rowsout = csvimportmerge(table, e) if e != 0 s = "Error " + .tostr(e, 10) + " importing data{d}{a}" else s = "Successfully imported " + .tostr(rowsout, 10) + " records{d}{a}" end if end if end if end function s function csvimportmerge(sbme1table table, integer error) dbCSVImport imp dbSBMEExport exp integer e, rowsout imp =@ dbCSVImport.new(",", "{d}{a}", 1, 2) imp.opensource("address.csv", "ISO-8859-1") exp =@ dbSBMEExport.new("O", .true, 1000) exp.sbme =@ table.sbme exp.sbmetable =@ table exp.createtable(table) exp.datasourcename = "Address@address.sbm" exp.merge = .true e = 0 rowsout = exp.export(imp, error=e) if e != 0 error=e end if end function rowsout
- AuthorPosts
- You must be logged in to reply to this topic.