Forum Discussion
tpoirier
13 years agoContributor
Got it figured out, below is working code to search for a users My Document Folder, append a file to open and then rotate through the first three rows and grad any data that isn't the sort cells or empty then place it in an array
Thanks for the help!
function GetDocuments() {
var WshShell, objShell, path;
MY_DOCUMENTS = 5;
objShell = new ActiveXObject("Shell.Application");
path = objShell.Namespace(MY_DOCUMENTS).Self.path; //determins the path to the users My Documents folder
FilePath = path + "\\APITestFile.xls"; //adds file name to open
var Excel = Sys.OleObject("Excel.Application");
Excel.Workbooks.Open(FilePath); //open the file at the file path built above
Excel.Visible = true;
var Uarray = [];
var Earray = [];
var Carray = [];
var e = "";
var U = "";
var C = "";
for(var i = 1; i < 4; i++) { //iterate through the first three rows of data in the file
var cell = VarToStr(Excel.Cells(i, 1).Value); //grab the cell value in the first col of the row
switch(cell) //figure out which array to place the value in
{
case "E":
for(var j=1; j < 13; j++) {
strStyle = VarToStr(Excel.Cells(i,j).Value);
if((e !== "") && ( e !== "E")) //check to see if it is empty or if the sort cell is selected
{
Earray
Log.Message(e);
}
}
break;
case "U":
for(var k=1; k < 13; k++) {
U = VarToStr(Excel.Cells(i, k).Value);
if((U !== "") && (U !== "U"))
{
Uarray
Log.Message(U);
}
}
break;
case "C":
for(var l=1; l < 13; l++) {
strC = VarToStr(Excel.cells(i, l).Value);
if((C !== "") && (C !== "C"))
{
Carray
Log.Message(C);
}
}
break;
default:
Log.Message("Value found that was not expected: " + cell); //log any errors found
break;
}
}
Excel.Workbooks.Close(); //close it up!