UnaCoder wrote:
Hi, I'm trying to use client side JavaScript from an HTML file to open
and make changes to an Excel SpreadSheet using ADO w/ ODBC. What a
pain it is to do this. Anyways, I am able to open the excel file but I
don't know how to use ADO to work with it's contents. So far I have
the following code that works:
<html>
<script>
window.onload = function () {
var ExcelSheet;
var sConnect = "DRIVER={Microsoft Excel Driver
(*.xls)};DBQ=P:\js-test.xls"
ExcelSheet = new ActiveXObject("ADODB.Connection");
ExcelSheet.Open(sConnect);
}
</script>
<body> =) </body>
</html>
Now that I have the sheet open, how do I manipulate it?
You don't have the Excel worksheet open. You have opened a connection
to it with your ADODB Connection object against which you can execute
SQL queries, etc. If you want to be able to get a reference to an excel
worksheet object and use its methods that would be something more like
this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Referencing Excel</title>
<script type="text/javascript">
var red = 3;
var excelobj = new ActiveXObject('Excel.Application');
excelobj.Application.Visible = true;
var wbobj = excelobj.Workbooks.Open('P:\js-test.xls');
var worksheet = wbobj.Worksheets.Item(1);
//alert(worksheet.Name);
if (worksheet.Range('A2').Value < 100){
worksheet.Range('A2').Font.ColorIndex = red;
alert('Warning! The number has fallen below 100.');
}
</script>
</head>
<body>
Nothing to see here...
</body>
</html>