在HTML中使用JavaScript中的ADO来更改电子表格 [英] Using ADO from JavaScript in HTML to change a spread sheet
问题描述
我正在尝试使用HTML文件中的客户端JavaScript打开
并使用带有ODBC的ADO对Excel SpreadSheet进行更改。这是多么痛苦的事情。无论如何,我可以打开excel文件,但是我不知道如何使用ADO来处理它的内容。到目前为止,我有以下代码有效:
< 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>
既然我打开了工作表,我该如何操作呢?
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?
推荐答案
UnaCoder写道:
UnaCoder wrote:
我正在尝试使用HTML文件中的客户端JavaScript打开
并使用带有ODBC的ADO对Excel SpreadSheet进行更改。 [...]
现在我打开了表格,我该如何操作它?
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. [...]
Now that I have the sheet open, how do I manipulate it?
我写了一篇关于此的文章Kuro5hin不久前。
https:/ /www.kuro5hin.org/story/2005/7/14/13942/7643
请不要告诉我使用innerHTML是多么邪恶;我已经知道了。我认为与DOM的混淆会减损文章中的
点。
如果您的目标是(仅限)Internet Explorer,请考虑使用HTA
(HTML应用程序)。
Josh
I wrote an article about this for Kuro5hin a while ago.
https://www.kuro5hin.org/story/2005/7/14/13942/7643
Please, don''t tell me how evil it is that I used innerHTML; I already
know that. I thought mucking with the DOM would have detracted from the
point of the article.
If you''re targeting (only) Internet Explorer, consider using an HTA
(HTML Application).
Josh
如何我将工作簿/工作表/列名称翻译为SQL?
应该是SELECT(sheetname)FROM(COLUMN)WHERE ...?
我尝试了SELECT * FROM A
导致错误没有这样的对象A
How to I translate the workbook/worksheet/column names to SQL?
should it be SELECT (sheetname) FROM (COLUMN) WHERE ... ?
I tried SELECT * FROM A
which caused an error "no such object "A"
UnaCoder写道:
UnaCoder wrote:
您好,我正在尝试使用HTML文件中的客户端JavaScript打开
并使用带有ODBC的ADO对Excel SpreadSheet进行更改。这样做真是太痛苦了。无论如何,我能够打开excel文件,但我不知道如何使用ADO来处理它的内容。到目前为止,我有以下代码可用:
< 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>
现在我打开了工作表,我该如何操作它?
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?
您没有打开Excel工作表。您已经使用ADODB Connection对象打开了一个连接
,您可以根据该对象执行
SQL查询等。如果您希望能够获得对excel
工作表对象并使用它的方法更像是
这个:
<!DOCTYPE html PUBLIC" ; - // W3C // DTD HTML 4.01 // EN"
" http://www.w3.org/TR/html4/strict.dtd">
< html>
< head>
< title>引用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(b) worksheet.Range(''A2'')。值< 10 0){
worksheet.Range(''A2'')。Font.ColorIndex = red;
alert(''警告!这个数字已经降到100以下。'');
}
< / script>
< / head>
< body>
这里没什么可看的......
< / body>
< / html>
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>
这篇关于在HTML中使用JavaScript中的ADO来更改电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!