例子:
在"c:\excel\book1.xls"存在一个EXCEL表book1.xsl,表的结构如下:
1 序号 名称 金额
2 1 张三 100
3 2 李四 200
4 3 王五 300序号字段不为空
注意:excel 起始行是1而不是为0 <%@language=vbscript %>
<%Set xlApp = server.CreateObject("Excel.Application")strsource = "c:\excel\book1.xls"Set xlbook = xlApp.Workbooks.Open(strsource)
Set xlsheet = xlbook.Worksheets(1) i=1
response.write "<table cellpadding=0 cellspacing=0 border=1 width=500>"
while xlsheet.cells(i,1)<>""
response.write "<tr>"
response.write " <td height=20 align=center width=100>" & xlsheet.Cells(i, 1) & "</td>"
response.write " <td height=20 align=center width=200>" & xlsheet.Cells(i, 2) & "</td>"
response.write " <td height=20 align=center width=200>" & xlsheet.Cells(i, 3) & "</td>"
response.write "</tr>"
i=i+1 wend
response.write "</table>"
set xlsheet=nothing
set xlbook=nothing
xlApp.quit '千万记住要加这一句,否则每运行一次你的机器里就增加一个excel进程,而且无法释放。我试过"set
xlApp=nothing"是不行的。
%>
在"c:\excel\book1.xls"存在一个EXCEL表book1.xsl,表的结构如下:
1 序号 名称 金额
2 1 张三 100
3 2 李四 200
4 3 王五 300序号字段不为空
注意:excel 起始行是1而不是为0 <%@language=vbscript %>
<%Set xlApp = server.CreateObject("Excel.Application")strsource = "c:\excel\book1.xls"Set xlbook = xlApp.Workbooks.Open(strsource)
Set xlsheet = xlbook.Worksheets(1) i=1
response.write "<table cellpadding=0 cellspacing=0 border=1 width=500>"
while xlsheet.cells(i,1)<>""
response.write "<tr>"
response.write " <td height=20 align=center width=100>" & xlsheet.Cells(i, 1) & "</td>"
response.write " <td height=20 align=center width=200>" & xlsheet.Cells(i, 2) & "</td>"
response.write " <td height=20 align=center width=200>" & xlsheet.Cells(i, 3) & "</td>"
response.write "</tr>"
i=i+1 wend
response.write "</table>"
set xlsheet=nothing
set xlbook=nothing
xlApp.quit '千万记住要加这一句,否则每运行一次你的机器里就增加一个excel进程,而且无法释放。我试过"set
xlApp=nothing"是不行的。
%>
Dim Driver, DBPath Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ=" & Server.MapPath( FileName )
Set GetExcelConnection = GetConnection( Driver & "! ReadOnly=0;" & DBPath )
End Function
我想找个直接是JSP写的,
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.awt.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>sample</title>
<meta http-equiv="Content-Type";content-type="text/html;charset=gb2312"%>
</head>
<body bgcolor=yellow>
<%
var xls = new ActiveXObject("Excel.Application");
xls.visible = true;//false;
xls.workbooks.open("abc.xls");
var xlsbook = xls.activeworkbook;
var xlssheet = xlsbook.worksheets(1);
xlssheet.cells(1,1).value = "js op excel";
xlsbook.save;
xls.quit;
xls = null;
delete xls;
%>
</body>
</html>
请各位再帮忙分析一下,
为什么出错误,
错误情况:
org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: -1 in the jsp file: nullGenerated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:64: not a statement
[javac] xlsbook.save;
[javac] ^
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:65: not a statement
[javac] xls.quit;
[javac] ^
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:58: cannot resolve symbol
[javac] symbol : class var
[javac] location: class org.apache.jsp.ex4_jsp
[javac] var xls = new ActiveXObject("Excel.Application");
[javac] ^
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:58: cannot resolve symbol
[javac] symbol : class ActiveXObject
[javac] location: class org.apache.jsp.ex4_jsp
[javac] var xls = new ActiveXObject("Excel.Application");
[javac] ^
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:61: cannot resolve symbol
[javac] symbol : class var
[javac] location: class org.apache.jsp.ex4_jsp
[javac] var xlsbook = xls.activeworkbook;
[javac] ^
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:62: cannot resolve symbol
[javac] symbol : class var
[javac] location: class org.apache.jsp.ex4_jsp
[javac] var xlssheet = xlsbook.worksheets(1);
[javac] ^
[javac] C:\Program Files\Tomcat 4.1\work\Standalone\localhost\_\ex4_jsp.java:67: cannot resolve symbol
[javac] symbol : class delete
[javac] location: class org.apache.jsp.ex4_jsp
[javac] delete xls;
[javac] ^
[javac] 7 errors