I have to read an excel which can have 'n' rows and 'n' columns and store the data in an array for processing.
For example the below:
Author Book No Value
ABC A 1 100
DEF D 2 20
I want to take the headers in a separate array and the Information rows in another.
Here is what I have so far:
Assuming the data starts from Row 13 in the excel worksheet-
var i, j, k ,l,m ,n;
i=13; j=1, k=0; m=0; n=0; // i represents the row and j represents excel column(A)
while(EApp.ActiveSheet.Cells(12,j).Value!="")
{
j=j+1; // Counting the Number of Columns (Header)
}
j=j-1; //decrementing the counter j by 1
k=j;
while(j!=0)
{
ArrField[j]=EApp.ActiveSheet.Cells(12,j).Value;
j=j-1;
}
This is what I tried, output is as expected, but is there a better way to code this? preferably with lesser variables.
while(EApp.ActiveSheet.Cells(i,1).Value!="undefined")
{
m=k;
j=0;
ArrData[i]=new Array(m);
while(m!=0)
{
ArrData[n][j]=EApp.ActiveSheet.Cells(i,m).Value;
m=m-1;
j=j+1;
}
n=n+1;
i=+1;
}
Also I need to read the arrays and store them into corresponding fields of another system. I'm a bit lost over here.
Sample Code: (Something like this)
SetFieldValue(ArrField[0],ArrData[0][0]);
Array Output:
Value,No,Book,Author (Header got in reverse order)
100,1,A,ABC,20,2,D,DEF (2 rows of Data also got in reverse order)
Any suggestions experts?
you can use csv's as dynamic arrays in a quite nice way. Here is my example code. I suggest to rewrite it to your needs and add some errorhandling.
Here is the table data:
Here is the code:
And here are the functions:
Now you have your dynamic array saved in mytestR. You can play with it like so: