会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
NRabbit
博客园
::
首页
::
博问
::
闪存
::
新随笔
::
联系
::
订阅
::
管理
::
公告
js读取本地excel文档数据
摘自:
http://blog.csdn.net/sainery/archive/2008/08/18/2790491.aspx
浏览器:IE
安全设置:默认
代码:
Code
1
<
script
>
2
function
readThis()
{
3
var
tempStr
=
""
;
4
var
filePath
=
document.all.upfile.value;
5
var
oXL
=
new
ActiveXObject(
"
Excel.application
"
);
6
var
oWB
=
oXL.Workbooks.open(filePath);
7
oWB.worksheets(
1
).select();
8
var
oSheet
=
oWB.ActiveSheet;
9
try
{
10
for
(
var
i
=
2
;i
<
46
;i
++
)
{
11
if
(oSheet.Cells(i,
2
).value
==
"
null
"
||
oSheet.Cells(i,
3
).value
==
"
null
"
)
12
break
;
13
var
a
=
oSheet.Cells(i,
2
).value.toString()
==
"
undefined
"
?
""
:oSheet.Cells(i,
2
).value;
14
tempStr
+=
(
"
"
+
oSheet.Cells(i,
2
).value
+
15
"
"
+
oSheet.Cells(i,
3
).value
+
16
"
"
+
oSheet.Cells(i,
4
).value
+
17
"
"
+
oSheet.Cells(i,
5
).value
+
18
"
"
+
oSheet.Cells(i,
6
).value
+
"
\n
"
);
19
}
20
}
catch
(e)
{
21
//
alert(e);
22
document.all.txtArea.value
=
tempStr;
23
}
24
document.all.txtArea.value
=
tempStr;
25
oXL.Quit();
26
CollectGarbage();
27
28
}
29
30
</
script
>
31
<
html
>
32
<
input
type
="file"
id
="upfile"
/><
input
type
="button"
onclick
="readThis();"
value
="读取"
>
33
<
br
>
34
<
textarea
id
="txtArea"
cols
=50
rows
=10
></
textarea
>
35
</
html
>
36
37
posted on
2008-08-19 08:56
kevin.nrabbit
阅读(
322
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部