at51178
12-30-2007, 04:41 PM
Hi
background info:
The project that I am working on takes an array of stock symbols and uses the req.open("GET",url,true) process to dynamically get content from a url and save the content in an excel spreadsheet.
Issue:
The issue that I am having is in the function call handleresponse,
if I just leave this line of code within the function
document.ajaxGet.dynamic.value = result.substring(endstring-4,endstring);
and after the functino I add this line of code
Book.ActiveSheet.Cells(i + 1,1).Value = mystocks[i];
Book.ActiveSheet.Cells(i + 1,2).Value = result.substring(endstring-4,endstring
the script does not work, but if I change the this line of code to
Book.ActiveSheet.Cells(i + 1,2).Value = 2
and run the script all the values are being entered into the spreadsheet.
I am not sure what I am doing wrong here, can some one help.
Thanks
Here is the code that I am using
<html>
<head>
<title>Fetch Page</title>
<script language="JavaScript1.2">
var mystocks = new Array();
mystocks[0] = "A";
mystocks[1] = "AAPL";
mystocks[2] = "MSFT";
var Excel, Book; // Declare the variables
Excel = new ActiveXObject("Excel.Application"); // Create the Excel application object.
Excel.Visible = false; // Make Excel invisible.
Book = Excel.Workbooks.Add() // Create a new work book.
for (i=0;i<mycars.length;i++)
{
var req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = handleResponse
req.open("GET", "http://quote.barchart.com/texpert.asp?sym=" + mystocks[i], true);
req.send(null);
function handleResponse() {
var charactercount = req.responseText.length
var startstring = req.responseText.indexOf("Overall Average");
var newresponse = req.responseText.substring(startstring,charactercount)
var endstring = newresponse.indexOf("-")
var result = newresponse.substring(0,endstring)
//var barhcartdata = document.write(result.substring(endstring-4,endstring))
if(req.readyState == 4)
if(req.status == 200)
document.ajaxGet.dynamic.value = result.substring(endstring-4,endstring);
//Book.ActiveSheet.Cells(i + 1,2).Value = result.substring(endstring-4,endstring);
else
document.ajaxGet.dynamic.value ="Error: " + req.status + " " + req.statusText;
}
Book.ActiveSheet.Cells(i + 1,1).Value = mystocks[i];
Book.ActiveSheet.Cells(i + 1,2).Value = result.substring(endstring-4,endstring)
}
Book.SaveAs("C:/TEST.xls");
Excel.Quit(); // Close Excel with the Quit method on the Application object.
</script>
</head>
<body>
<FORM method="GET" name="ajaxGet" action="">
<INPUT type="BUTTON" value="Submit" ONCLICK="submitForm()">
<INPUT type="text" name="dynamic" value="">
</FORM>
</body>
</html>
background info:
The project that I am working on takes an array of stock symbols and uses the req.open("GET",url,true) process to dynamically get content from a url and save the content in an excel spreadsheet.
Issue:
The issue that I am having is in the function call handleresponse,
if I just leave this line of code within the function
document.ajaxGet.dynamic.value = result.substring(endstring-4,endstring);
and after the functino I add this line of code
Book.ActiveSheet.Cells(i + 1,1).Value = mystocks[i];
Book.ActiveSheet.Cells(i + 1,2).Value = result.substring(endstring-4,endstring
the script does not work, but if I change the this line of code to
Book.ActiveSheet.Cells(i + 1,2).Value = 2
and run the script all the values are being entered into the spreadsheet.
I am not sure what I am doing wrong here, can some one help.
Thanks
Here is the code that I am using
<html>
<head>
<title>Fetch Page</title>
<script language="JavaScript1.2">
var mystocks = new Array();
mystocks[0] = "A";
mystocks[1] = "AAPL";
mystocks[2] = "MSFT";
var Excel, Book; // Declare the variables
Excel = new ActiveXObject("Excel.Application"); // Create the Excel application object.
Excel.Visible = false; // Make Excel invisible.
Book = Excel.Workbooks.Add() // Create a new work book.
for (i=0;i<mycars.length;i++)
{
var req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = handleResponse
req.open("GET", "http://quote.barchart.com/texpert.asp?sym=" + mystocks[i], true);
req.send(null);
function handleResponse() {
var charactercount = req.responseText.length
var startstring = req.responseText.indexOf("Overall Average");
var newresponse = req.responseText.substring(startstring,charactercount)
var endstring = newresponse.indexOf("-")
var result = newresponse.substring(0,endstring)
//var barhcartdata = document.write(result.substring(endstring-4,endstring))
if(req.readyState == 4)
if(req.status == 200)
document.ajaxGet.dynamic.value = result.substring(endstring-4,endstring);
//Book.ActiveSheet.Cells(i + 1,2).Value = result.substring(endstring-4,endstring);
else
document.ajaxGet.dynamic.value ="Error: " + req.status + " " + req.statusText;
}
Book.ActiveSheet.Cells(i + 1,1).Value = mystocks[i];
Book.ActiveSheet.Cells(i + 1,2).Value = result.substring(endstring-4,endstring)
}
Book.SaveAs("C:/TEST.xls");
Excel.Quit(); // Close Excel with the Quit method on the Application object.
</script>
</head>
<body>
<FORM method="GET" name="ajaxGet" action="">
<INPUT type="BUTTON" value="Submit" ONCLICK="submitForm()">
<INPUT type="text" name="dynamic" value="">
</FORM>
</body>
</html>