yoduh
06-14-2007, 03:06 PM
anytime i refresh my website with this code, EXCEL.EXE pops into memory, and with each refresh and each load of the page i see one more EXCEL.EXE process begin running in the task manager, and it stays there till i end every single process myself. I'm very new with javascript so bear with me as you go through my code, it's probably not close to being the best it can be.
what the script does is open displayinfo.xls to read from, and starting at cell B3, grabs the value which would be something like "W708" (for 2007 Week 08), then i make it into a character string so i can find the corresponding <td> in my HTML with the matching id of "W708". Then it grabs more info from Excel from a cell above and below the "W708" and then all the info together formats the <td> cell.
the blank variable keeps track of how many times the code reads a blank cell (after 2 blank columns ive effectively searched the whole row of weeks in excel, so i use that as my signal to stop).
<script language="javascript">
function excell()
{
var idTmr = "";
var excel = new ActiveXObject("Excel.Application");
excel.visible=false;
var excel_file = excel.Workbooks.Open("displayinfo.xls");
var excel_sheet = excel.Worksheets("Sheet1");
var y=3;
var x=2;
var blank=0;
var divCollection = document.getElementsByTagName("td");
data = excel_sheet.Cells(y,x).Value;
week = new String(data);
while(blank<=1)
{
if(week!="")
{
data = excel_sheet.Cells(y,x).Value;
week = new String(data);
for (var i=0; i<divCollection.length; i++) {
if(divCollection[i].getAttribute("id") == week) {
ms=excel_sheet.Cells(y-1,x).Value;
ac=excel_sheet.Cells(y+1,x).Value;
findMeText=ms;
divCollection[i].innerHTML=findMeText;
if(ac=="Yes" || ac=="yes")
document.getElementById(week).style.backgroundColor='99CCFF'; //blue=99CCFF. green=99FF66. yellow=FFFF99. red=FF6666. grey=CCCCCC
else if(ac=="No" || ac=="no")
document.getElementById(week).style.backgroundColor='FF6666';
else
document.getElementById(week).style.backgroundColor='99FF66';
}
}
}
else
blank=blank+1;
x=x+1;
}
excel.Quit();
excel=null;
idTmr=window.setInterval("Cleanup();",1);
}
function Cleanup()
{
window.clearInterval(idTmr);
CollectGarbage();
}
</script>
i googled this - http://support.microsoft.com/kb/266088 and thats where i got the code for the last part of my script with excel.Quit(); and the Cleanup() function. this actually use to work before I had implemented a while loop. but before i had the while loop i was just calling the script everytime from each <td> tag in my HTML feeding the script the info it now grabs on its own from excel, except it was capable of using the value below the 'week' row, which i use to determine background color. i don't know why it wont work now, anyone have a possible answer? :confused:
what the script does is open displayinfo.xls to read from, and starting at cell B3, grabs the value which would be something like "W708" (for 2007 Week 08), then i make it into a character string so i can find the corresponding <td> in my HTML with the matching id of "W708". Then it grabs more info from Excel from a cell above and below the "W708" and then all the info together formats the <td> cell.
the blank variable keeps track of how many times the code reads a blank cell (after 2 blank columns ive effectively searched the whole row of weeks in excel, so i use that as my signal to stop).
<script language="javascript">
function excell()
{
var idTmr = "";
var excel = new ActiveXObject("Excel.Application");
excel.visible=false;
var excel_file = excel.Workbooks.Open("displayinfo.xls");
var excel_sheet = excel.Worksheets("Sheet1");
var y=3;
var x=2;
var blank=0;
var divCollection = document.getElementsByTagName("td");
data = excel_sheet.Cells(y,x).Value;
week = new String(data);
while(blank<=1)
{
if(week!="")
{
data = excel_sheet.Cells(y,x).Value;
week = new String(data);
for (var i=0; i<divCollection.length; i++) {
if(divCollection[i].getAttribute("id") == week) {
ms=excel_sheet.Cells(y-1,x).Value;
ac=excel_sheet.Cells(y+1,x).Value;
findMeText=ms;
divCollection[i].innerHTML=findMeText;
if(ac=="Yes" || ac=="yes")
document.getElementById(week).style.backgroundColor='99CCFF'; //blue=99CCFF. green=99FF66. yellow=FFFF99. red=FF6666. grey=CCCCCC
else if(ac=="No" || ac=="no")
document.getElementById(week).style.backgroundColor='FF6666';
else
document.getElementById(week).style.backgroundColor='99FF66';
}
}
}
else
blank=blank+1;
x=x+1;
}
excel.Quit();
excel=null;
idTmr=window.setInterval("Cleanup();",1);
}
function Cleanup()
{
window.clearInterval(idTmr);
CollectGarbage();
}
</script>
i googled this - http://support.microsoft.com/kb/266088 and thats where i got the code for the last part of my script with excel.Quit(); and the Cleanup() function. this actually use to work before I had implemented a while loop. but before i had the while loop i was just calling the script everytime from each <td> tag in my HTML feeding the script the info it now grabs on its own from excel, except it was capable of using the value below the 'week' row, which i use to determine background color. i don't know why it wont work now, anyone have a possible answer? :confused: