Copy link to clipboard
Copied
I have a CSV file that I can load into my adobe form. It has a format like this:
adata00;adata01,adata02;adata03;adata04;adata05;adata06;
bdata10;bdata11;bdata12;bdata13;bdata14;bdata15;bdata16;
cdata20;cdata21;cdata22;cdata23;cdata24;cdata25;cdata26;
etc.
I'm loading it into a (hidden) text field called data_lijst. Works fine! Now I'm trying to build a 2D matrix from it. My current code looks like this:
var getData = this.getField("data_lijst").value.split("\r"); // getting the data from the field, splitting it on the rulebrakes and building a one dimensional array. A check if it works in the shape of this code works fine this.getField("checkfield").value = getData[0] which works all the way up to the end of the CSV file (in Excel its approx. 378 lines). It returns nicely:
adata00;adata01,adata02;adata03;adata04;adata05;adata06;
So now we want to combine that with loop over that array and build a new 2D one:
var matrix = new Array () //building an empty new array, not sure if this line is needed.
var getData = this.getField("data_lijst").value.split("\r"); //build an array called getData and fill it with 378 elements
for (var i=0; i<getData.length; i++) //loop over the array
{
getData[i].split(";"); //trying to split every single element (i) of the getData array into a new (sub)array
matrix.push(getData[i]); // filling the new array called matrix with the values assuming getData[i] is now a subarray
}
this.getField("field00").value = matrix[0][0]; // returns a instead of adata
this.getField("field10").value = matrix[1][0]; // returns b instead of bdata
Tried to use slice too and replace the original index i with a new subarray.
for (var i = 0; i < getData.length; i++)
{
var x = new Array(getData[i].split(";")); //make a new array called x
getData.slice(i,(i ++),x); //replace I until i+1 with the new array x, should be an array in an array
}
Same result L
this.getField("field00").value = getData[0][0]; // returns a instead of adata
I am so darn close. Please, how to do this properly? Much appreciated!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
For filling the matrix use:
matrix.push(getData[i].split(";"));
Copy link to clipboard
Copied
Many thanks Bernd. I'm surprised how I've missed this and how elegant the solution. I'm just hacking my way though javascript with no formal training and hardly any experience, so I've still got a lot to learn. Thanks for helping me out!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more