P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
LoadVars
:
Parse Excel-generated CSV files
author:
mga
[+]
,
Submitted: 10.16.03 2p
• Last Edit: 05.19.07 10a
/**************************************************************************** Copyright (C) 2003-2007 Mauricio Giraldo http://www.pingpongestudio.com History ------- May 19 / 2005: The destination array name was wrongly created Oct 16 / 2003: Version 1 - Made for parsing Excel-generated CSVs. Will generate a 2-D array You must create a LoadVars object for text parsing and a MovieClip object that will receive the data loaded: _source = URL to the CSV to be parsed _destination = movie clip that will receive CSV data _arrayName = name of the array to be created in _destination with the data _ignoreLastRow = Excel sometimes generates an empty last row _ignoreFirstRow = the first row may contain column headers *****************************************************************************/ LoadVars.prototype.process = function () { var _lv = this; var i,item,line_array,_array,tipo=false; _lv.load(_lv._source); _lv._destination[_lv._arrayName] = new Array(); _lv.onLoad = function (e){ if (e) { var i,line_array; trace("Parsing data..."); for (item in _lv) { if (typeof(_lv[item]) == "string" && item != "_source" && item != "_arrayName") { line_array = item.split("\r\n"); if (_lv._ignoreFirstRow) { line_array.shift(); trace("First row ignored"); } if (_lv._ignoreLastRow) { line_array.pop(); trace("Last row ignored"); } _array = new Array(); for (i=0;i<line_array.length;i++) { _array[i] = line_array[i].split(","); } trace("Total rows parsed: " + line_array.length); trace("Total cols parsed: " + _array[0].length); _lv._destination[_lv._arrayName] = _array; _lv.onProcessed(_lv._destination[_lv._arrayName]); tipo = true; } } if (!tipo) { trace(_lv._src + " not a valid Excel CSV file!"); } } else { trace("Error loading file!"); } } }
usage
Version 1 - Made for parsing Excel-generated CSVs. Will generate a 2-D array You must create a LoadVars object for text parsing and a MovieClip object that will receive the data loaded: _source = URL to the CSV to be parsed _destination = movie clip that will receive CSV data _arrayName = name of the array to be created in _destination with the data _ignoreLastRow = Excel sometimes generates an empty last row Example: [code] #include "mgaCSV2003.as" function go (){ var myXMLsrc = "separado.csv"; var parseMe = new LoadVars(); parseMe._source = myXMLsrc; parseMe._destination = this.createEmptyMovieClip("myinfo",10); parseMe._ignoreLastRow = true; parseMe._ignoreFirstRow = false; parseMe._arrayName = "data"; parseMe.process(); parseMe.onProcessed = function () { trace("parsing done"); } } go(); [/code]
msg
1
{
CoDo
[+]
, posted: 05.21.06 5a•-, top
[^]
}
Very nice!
I wonder, could you give me a clou or example how to show the loaded CSV in my movieclip?
Thank you every way,
Cor
msg
2
{
mga
[+]
, posted: 05.21.06 2p•-, top
[^]
}
this proto puts your csv in a 2d array named _arrayName under _destination. suppose _destination is someclip and _arrayName is data:
trace (someclip.data[0][1]); // will show first row second column
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@