Welcome! Log In Create A New Profile

Advanced

Script for importing data

Posted by Joel 
Joel
Script for importing data
February 25, 2009 06:18PM
Does anyone have a sample of some script to import data? If I understand it correctly you can make a custom map that WebDev will use when importing data - is this true? If I could see a sample of the code, that would get me going faster!

Thanks!
DarrenF
Re: Script for importing data
February 26, 2009 02:29AM
Hi Joel,

Although you don't say what format your source data is in, here's a script I wrote to import Countries from an Excel file sourced from the ISO standards web site:

IDXLSFile is int
iNo_rows is int
glocaliIResult is int

// Open the Currencies excel file
IDXLSFile = xlsOpen("c:\My Projects\InterPoint\Extract Files for Import\currencies.xls")

// If the Excel file was found, then carry on processing
// ELSE
// Report an error
IF IDXLSFile <> -1 THEN
	
	// Get number of rows in the Excel file
	iNo_rows = xlsNbRow(IDXLSFile)
	
	// Test for existence of Country table
	IF NOT HOpen(Country,hOReadWrite) THEN
		Error("Unable to locate the required Country database table!")
		RETURN
	END
		
	// HCreation will delete and re-create these tables and also reset all the rec no's and auto IDs
	HCreation(Country)
		
	// Process each row of the Excel file
	// Start at row 2 to ignore the Excel title row...
	FOR glocaliNV_Row = 2 TO iNo_rows
		
		// Country Details
		Country.cCountryCode = xlsData(IDXLSFile,glocaliNV_Row,1)
		Country.cCountryName = xlsData(IDXLSFile,glocaliNV_Row,5)
		Country.cCurrencyCode = xlsData(IDXLSFile,glocaliNV_Row,2)
		Country.nCurrencyCode = xlsData(IDXLSFile,glocaliNV_Row,3)
		Country.cCurrencyDesc = xlsData(IDXLSFile,glocaliNV_Row,4)
		Country.bActiveCountry = xlsData(IDXLSFile,glocaliNV_Row,6)
		Country.bActiveCurrency = xlsData(IDXLSFile,glocaliNV_Row,7)
		Country.cCurrencySymbol = ""
		Country.dtCreated = DateSys + TimeSys
		Country.cNotes = "Auto loaded from ISO import file on " + DateToString(DateSys())
		
		// Write the data to the database
		HAdd(Country)
						
	END
	
	// Close XLS file
	xlsClose(IDXLSFile)
		
ELSE
	Info(xlsMsgError(IDXLSFile))	

END

Happy to share - hope this helps... :spos:
Joel
Re: Script for importing data
February 26, 2009 05:03PM
That looks awesome! That will really help me - I appreciate it!

Be well,

J
Hans60
Re: Script for importing data
February 28, 2009 02:38PM
thanks for posting the code I was also looking for that!
Hans
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: