Lasso Soft Inc. > Home


AuthorJason Huck
Posted14 Oct 2005
Updated28 Sep 2012
More by this author...


Serves a CSV file. Optionally accepts an array of field names and an array of arrays, where each nested array represents one line of data.

If called within an inline without those parameters, the tag will use [field_names] and [rows_array].

Sample Usage

	found_count > 0 ? serve_csv;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

	-description='Serves a CSV file.'
		!local_defined('fields') && !field_names->size,
		'[serve_csv] must be called with an array of field names or be within an inline where[field_names] contains values.'

		!local_defined('rows') && !rows_array->size,
		'[serve_csv] must be called with an array of row data or be within an inline where [rows_array] contains values.'

	!local_defined('fields') ? local('fields' = field_names);
	!local_defined('rows') ? local('rows' = rows_array);

	local('out' = string);
	iterate(#fields, local('f'));
		#out += #f;			
		loop_count == #fields->size ? #out += '\r\n' | #out += ',';

	iterate(#rows, local('r'));
		iterate(#r, #f);
			#f = string(#f);
			#out += '"' + #f + '"';				
			loop_count == #r->size ? #out += '\r\n' | #out += ',';

		-file=(local_defined('filename') ? #filename | 'results.csv'),


28 Oct 2009, Samuel Cohen

Line 64?

Looks like there's a wee li'l error on line 64. Seems a '>' (closing angle bracket) got replaced with '>'

Line 64 should read:
loop_count == #fields->size ? #out += '\r\n' | #out += ',';

Regardless... this tag has made my life easier on quite a few occasions. Thanks!

20 Apr 2008, Asle Benoni

Much work to change this to "serve_excel"?

Great tag. I tried to change this to serve Excel files but not sure I did it correctly. Changed line 32 "..#out += ','.. " to "..#out += '\t'.. " and line 38 to #f->replace('"','') and line 47 to "-type='text/excel' "

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft