Importing an array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Importing an array

Martin Jaekel
Hi,

I would like to import a column of numeric values from excel (or from a txt
file) into my macro.

Can anybody help?

Thanks,
Martin
Reply | Threaded
Open this post in threaded view
|

Re: Importing an array

Michael Doube-2
Hi Martin

I've done something like that before for CSV data in this macro:
http://doube.org/files/Umis_Array0.53.txt

The sections of interest are these:
//Open the array file which must be a csv list like x,y,f
string = File.openAsString("");

//Split the CSV file into an array of lines
lines = split(string, "\n");
nindents = lengthOf(lines);

Then I split each line at the commas like:
data = split(lines[n], "\,");

so data[x] holds the data sitting at row n and column x

This function uses the above method:
function parse_moduli() {
//parse the moduli file
        modulus_min = 99999999;
        modulus_max = 0;
        moduli_file = File.openAsString("");
        moduli_lines = split(moduli_file, "\n");
        moduli = newArray(nindents);
        for (m=0; m<lengthOf(moduli_lines); m++){
                moduli_n= split(moduli_lines[m], "\,");
                if (isNaN(moduli_n[1]) == true) moduli[m] = 0; else moduli[m] =  
parseFloat(moduli_n[1]);
                if (moduli[m] < modulus_min) modulus_min = moduli[m];
                if (moduli[m] > modulus_max) modulus_max = moduli[m];
        }
}


Hopefully that's enough to get you started

Mike

Quoting Martin Jaekel <[hidden email]>:

> Hi,
>
> I would like to import a column of numeric values from excel (or from a txt
> file) into my macro.
>
> Can anybody help?
>
> Thanks,
> Martin
>