我也在找呢,一起问吧以前有个程序可以实现对jxl封装的操作
---------------------------------
就是在jsp里写:
<form name="frm" method="post" action="../../xls/ReadXls2MultiTab.jsp"><input type="submit" name="Submit23" value="导入" class="newbutton">
<input type=hidden name="query" value="INSERT INTO WUJING (ID,NAME) values (:0,:1)">
<input type=hidden name="nextpage" value="\regStudentServlet?act=show&ZSZYH=<%=request.getParameter("ZSZYH")%>&ZSPC_MC=<%=request.getParameter("ZSPC_MC")%>&XLCC_MC=<%=request.getParameter("XLCC_MC")%>&ZY_MC=<%=request.getParameter("ZY_MC")%>">
<input type=hidden name="beginrow" value="1">
<input type=hidden name="endrow" value=""></form>
--------------------------------------
ReadXls2MultiTab.jsp
<%@ page contentType="text/html;charset=GB2312"
import="java.util.*,java.io.File,java.sql.*,wujingsys.xls.*,wujingsys.xls.upload.*"%>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
<META name="IBM:DeviceType" content="_TV Mode (640x480)_">
<LINK href="../../theme/style.css" rel="stylesheet" type="text/css">
<TITLE>正在导入数据...</TITLE>
</HEAD>
<BODY>
<%@include file="../header.htm"%>
<%
SmartUpload mySmartUpload=new SmartUpload();
String realpath="";
realpath = "";
int count;
mySmartUpload.initialize(pageContext);
mySmartUpload.setTotalMaxFileSize(Integer.MAX_VALUE);
mySmartUpload.upload();
try {
count = mySmartUpload.save(realpath); } catch (Exception e) {
out.println(e.toString());
}
String fn=mySmartUpload.getFiles().getFile(0).getFileName();
java.io.File f=new File(realpath+"/"+fn);
String newfn=String.valueOf((new java.util.Date()).getTime());
System.out.println(realpath+"/"+newfn);
f.renameTo(new File(realpath+"/"+newfn));
fn=newfn;
Hashtable parame=new Hashtable();
java.util.Enumeration e = mySmartUpload.getRequest().getParameterNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String[] values = mySmartUpload.getRequest().getParameterValues(key);
for(int i = 0; i < values.length; i++) {
parame.put(key,values[i]);
}
}
String hquery=(String)parame.get("hquery");
String tquery=(String)parame.get("tquery");
String squery=(String)parame.get("query");
String sbegrow=(String)parame.get("begrow");
String sendrow=(String)parame.get("endrow");
String isIgnore=(String)parame.get("isIgnore");
String isDisplayMsg=(String)parame.get("isDisplayMsg");
String nextpage=(String)parame.get("nextpage"); isIgnore=(isIgnore==null?"true":isIgnore);
isDisplayMsg=(isDisplayMsg==null?"true":isDisplayMsg);
int begrow=1,endrow=-1;
try{
begrow=Integer.parseInt(sbegrow);
}catch(NumberFormatException fm){
begrow=1;
}
try{
endrow=Integer.parseInt(sendrow);
}catch(NumberFormatException fm){
endrow=-1;
}
ReadXLS r =null;
try{
//System.out.println(realpath);
r = new ReadXLS(realpath+"/"+fn);
r.setDataRow(begrow,endrow);
r.setQuery(IString.split(squery,";"));
r.setHeadQuery(IString.split(hquery,";"));
r.setTaileQuery(IString.split(tquery,";"));
//是否忽略错误
if(isIgnore.equals("false"))
r.setisIgnoreErr("false");//default ignore all errors
r.open();
}catch(Exception ex){
ex.printStackTrace();
out.println("<script>");
out.println("alert('发生意外错误 \n 文件格式错误或与Microsoft Excel不兼容!');");
out.println("history.back();");
out.println("</script>");
}
try {
if(!isIgnore.equals("exit")){
r.read();
r.close();
}
} catch (Exception w) {
r.close();
w.printStackTrace();
}
if(nextpage==null||nextpage.equals("null")||nextpage.length()<1){
out.println("<script>");
out.println("history.go(-2)");
out.println("</script>");
}
else{
//System.out.println(nextpage);
response.sendRedirect(nextpage);
return;
}
%>
<BR><BR><BR><BR><BR><BR><BR><BR>
<center><input type=button onclick="history.go(-2)" value="返 回"></center>
</BODY>
</HTML>
--------------------------------------
wujingsys.xls负责内部处理现在16行mySmartUpload.upload();在报错:
java.lang.StringIndexOutOfBoundsException: String index out of range: -5883
at java.lang.String.checkBounds(String.java:283)
at java.lang.String.<init>(String.java:370)
at wujingsys.xls.upload.SmartUpload.upload(SmartUpload.java:214)
at _jsp._xls._readxlsmutitabaction__jsp._jspService(/xls/ReadXlsMutiTabAction.jsp:20)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:190)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)-------------------------------------
已知wujingsys.xls包以前是可以运转的
不应该是内部有问题
有没有高手用过这个??
给帮忙看看!!
---------------------------------
就是在jsp里写:
<form name="frm" method="post" action="../../xls/ReadXls2MultiTab.jsp"><input type="submit" name="Submit23" value="导入" class="newbutton">
<input type=hidden name="query" value="INSERT INTO WUJING (ID,NAME) values (:0,:1)">
<input type=hidden name="nextpage" value="\regStudentServlet?act=show&ZSZYH=<%=request.getParameter("ZSZYH")%>&ZSPC_MC=<%=request.getParameter("ZSPC_MC")%>&XLCC_MC=<%=request.getParameter("XLCC_MC")%>&ZY_MC=<%=request.getParameter("ZY_MC")%>">
<input type=hidden name="beginrow" value="1">
<input type=hidden name="endrow" value=""></form>
--------------------------------------
ReadXls2MultiTab.jsp
<%@ page contentType="text/html;charset=GB2312"
import="java.util.*,java.io.File,java.sql.*,wujingsys.xls.*,wujingsys.xls.upload.*"%>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
<META name="IBM:DeviceType" content="_TV Mode (640x480)_">
<LINK href="../../theme/style.css" rel="stylesheet" type="text/css">
<TITLE>正在导入数据...</TITLE>
</HEAD>
<BODY>
<%@include file="../header.htm"%>
<%
SmartUpload mySmartUpload=new SmartUpload();
String realpath="";
realpath = "";
int count;
mySmartUpload.initialize(pageContext);
mySmartUpload.setTotalMaxFileSize(Integer.MAX_VALUE);
mySmartUpload.upload();
try {
count = mySmartUpload.save(realpath); } catch (Exception e) {
out.println(e.toString());
}
String fn=mySmartUpload.getFiles().getFile(0).getFileName();
java.io.File f=new File(realpath+"/"+fn);
String newfn=String.valueOf((new java.util.Date()).getTime());
System.out.println(realpath+"/"+newfn);
f.renameTo(new File(realpath+"/"+newfn));
fn=newfn;
Hashtable parame=new Hashtable();
java.util.Enumeration e = mySmartUpload.getRequest().getParameterNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String[] values = mySmartUpload.getRequest().getParameterValues(key);
for(int i = 0; i < values.length; i++) {
parame.put(key,values[i]);
}
}
String hquery=(String)parame.get("hquery");
String tquery=(String)parame.get("tquery");
String squery=(String)parame.get("query");
String sbegrow=(String)parame.get("begrow");
String sendrow=(String)parame.get("endrow");
String isIgnore=(String)parame.get("isIgnore");
String isDisplayMsg=(String)parame.get("isDisplayMsg");
String nextpage=(String)parame.get("nextpage"); isIgnore=(isIgnore==null?"true":isIgnore);
isDisplayMsg=(isDisplayMsg==null?"true":isDisplayMsg);
int begrow=1,endrow=-1;
try{
begrow=Integer.parseInt(sbegrow);
}catch(NumberFormatException fm){
begrow=1;
}
try{
endrow=Integer.parseInt(sendrow);
}catch(NumberFormatException fm){
endrow=-1;
}
ReadXLS r =null;
try{
//System.out.println(realpath);
r = new ReadXLS(realpath+"/"+fn);
r.setDataRow(begrow,endrow);
r.setQuery(IString.split(squery,";"));
r.setHeadQuery(IString.split(hquery,";"));
r.setTaileQuery(IString.split(tquery,";"));
//是否忽略错误
if(isIgnore.equals("false"))
r.setisIgnoreErr("false");//default ignore all errors
r.open();
}catch(Exception ex){
ex.printStackTrace();
out.println("<script>");
out.println("alert('发生意外错误 \n 文件格式错误或与Microsoft Excel不兼容!');");
out.println("history.back();");
out.println("</script>");
}
try {
if(!isIgnore.equals("exit")){
r.read();
r.close();
}
} catch (Exception w) {
r.close();
w.printStackTrace();
}
if(nextpage==null||nextpage.equals("null")||nextpage.length()<1){
out.println("<script>");
out.println("history.go(-2)");
out.println("</script>");
}
else{
//System.out.println(nextpage);
response.sendRedirect(nextpage);
return;
}
%>
<BR><BR><BR><BR><BR><BR><BR><BR>
<center><input type=button onclick="history.go(-2)" value="返 回"></center>
</BODY>
</HTML>
--------------------------------------
wujingsys.xls负责内部处理现在16行mySmartUpload.upload();在报错:
java.lang.StringIndexOutOfBoundsException: String index out of range: -5883
at java.lang.String.checkBounds(String.java:283)
at java.lang.String.<init>(String.java:370)
at wujingsys.xls.upload.SmartUpload.upload(SmartUpload.java:214)
at _jsp._xls._readxlsmutitabaction__jsp._jspService(/xls/ReadXlsMutiTabAction.jsp:20)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:190)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)-------------------------------------
已知wujingsys.xls包以前是可以运转的
不应该是内部有问题
有没有高手用过这个??
给帮忙看看!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货