allen
          專注于java ee技術,包括struts,jsf,webwork,spring,hibernate,ibatis
          posts - 7,  comments - 9,  trackbacks - 0

          jxl在操作Excel文件時,要求文件需要保存在服務器端
          可以先用SmartUpload將文件上傳至服務器,再進行操作
          下面是個例子

          <%@ page language="java" contentType="text/html; charset=GBK" %>
          <%@page import="java.sql.*"%>
          <%@page import="java.io.*"%>
          <%@page import="java.util.*,jxl.*,ConnDatabase.SDatabase"%>
          <%@ page import="com.jspsmart.upload.*"%>
          <%@ include file="../public_js/yonghuhuodong.jsp" %>
          <script language="javascript" src="../public_js/public.js"></script>

          <LINK href="../class/<%=session.getAttribute("FactColorC") %>" rel=stylesheet>
          <script language=javascript src="../sale/js/mad.js"> </script>

          <jsp:useBean id="ViewBean" scope="page" class="ConnDatabase.SDatabase"/>

          ?

          <jsp:useBean? id="myUpload"? scope="page"? class="com.jspsmart.upload.SmartUpload" />

          ?

          <%

          String trace = "";
          String fileNames = request.getParameter("fname");
          //out.println(fileNames);
          //String fsections = request.getParameter("fsection");

          if(fileNames!=null && !fileNames.equals("")){
          ?try{
          ??//實例化上載bean
          ??com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
          ??//初始化
          ??mySmartUpload.initialize(pageContext);
          ??//設置上載的最大值
          ??mySmartUpload.setMaxFileSize(500 * 1024*1024);
          ??//上載文件
          ??mySmartUpload.upload();
          ??//循環(huán)取得所有上載的文件
          ??// 建立上傳目錄
          ??//java.io.File fileMkDir = new java.io.File(strSavePath);
          ??//fileMkDir.mkdirs();
          ??for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
          ???//取得上載的文件
          ???com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
          ???if (!myFile.isMissing())
          ???{
          ????//取得上載的文件的文件名
          ????String myFileName=myFile.getFileName();
          ????//取得不帶后綴的文件名
          ????String? suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
          ????//取得后綴名
          ????String? ext= mySmartUpload.getFiles().getFile(0).getFileExt();?
          ????//取得文件的大小?
          ????int fileSize=myFile.getSize();
          ????//保存路徑
          ????String aa=getServletContext().getRealPath("/")+"jsp\\upload\\";
          ????trace=aa+myFileName;
          ????//System.out.println(trace);
          ????//取得別的參數
          ????String explain=(String)mySmartUpload.getRequest().getParameter("files");
          ????String send=(String)mySmartUpload.getRequest().getParameter("SaveEPrice");
          ????//將文件保存在服務器端
          ????myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
          ???}
          ??}
          ?}catch(Exception e){
          ??System.out.println(e.getMessage());
          ??e.printStackTrace();
          ?}
          }
          //System.out.println("-----------------");
          ?java.io.File?? f=?? new?? java.io.File(trace);??
          ? f=f.getCanonicalFile();??
          ? InputStream?? is?? =?? new?? FileInputStream(f);??
          ? jxl.Workbook?? rwb?? =?? Workbook.getWorkbook(is);?
          ?? Sheet?? rs?? =?? rwb.getSheet(0);??
          ? int?? rsrows=rs.getRows();??
          ??? int allRec=rs.getRows();///得到該sheet的行數
          ???? int row = rs.getColumns(); //得到列數
          ?// out.print("行:"+allRec+"--列:"+row);
          ?? // Cell?? c1=rs.getCell(0,1);
          ? //? String s=c1.getContents();
          //?out.println(s);
          //List list=new ArrayList();
          String s1="";
          String s2="";
          String s3="";
          String s4="";
          String s5="";
          String s6="";
          String s7="";
          String s8="";
          String s9="";
          String custNo="";
          try{

          ?for(int?? i=2;i<allRec;i++){
          ??
          ?? for(int j=1;j<row;j++){
          ??????????
          ??????????
          ?????????? // c.setSection(fsections);? /
          ???//s1=fsections;
          ??????????? Cell?? c1=rs.getCell(1,i);
          ???Cell?? c2=rs.getCell(2,i);
          ????? Cell?? c3=rs.getCell(3,i);
          ???Cell?? c4=rs.getCell(4,i);
          ??????????? Cell?? c5=rs.getCell(5,i);
          ??????????? Cell?? c6=rs.getCell(6,i);
          ??????????? Cell?? c7=rs.getCell(7,i);
          ??????????? Cell?? c8=rs.getCell(8,i);
          ???//custNo=getMaxSequrence(fsections);
          ???s2=c1.getContents();
          ???s3=c2.getContents();
          ???s4=c3.getContents();
          ???s5=c4.getContents();
          ???s6=c5.getContents();
          ???s7=c6.getContents();
          ???s8=c7.getContents();
          ??????????? s9=c8.getContents();
          ???/*c.setCustName(c1.getContents());
          ???c.setCus_Sex(c2.getContents());
          ???c.setRoomNo(c3.getContents());
          ???c.setRoomNo(c4.getContents());???
          ???c.setAddress(c5.getContents());???
          ???c.setCardNo(c6.getContents());???????
          ???c.setPhone(c7.getContents());???????
          ???c.setRemark(c8.getContents());*/
          //???String fff=c1.getContents();?????????????
          ?? }
          ??
          ??????????????? }
          ?
          ??
          ?}
          ?out.println("<script language='javascript'>alert('成功添加');window.opener.location.reload();window.close();</script>");?
          }catch(Exception e){
          ?out.println("<script language='javascript'>alert('您提供的文件不正確!!!');window.close();</script>");
          }
          ?
          ?
          %>

          posted on 2006-10-11 18:29 robbin163 閱讀(582) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 贵定县| 苏尼特左旗| 比如县| 含山县| 天柱县| 建平县| 通州区| 龙南县| 井研县| 股票| 龙口市| 海丰县| 商南县| 布尔津县| 芷江| 塘沽区| 昆山市| 丹阳市| 阳西县| 华安县| 黑河市| 原平市| 红桥区| 得荣县| 伊吾县| 从江县| 虹口区| 桃园市| 宾阳县| 建平县| 宁乡县| 汪清县| 石渠县| 崇礼县| 威远县| 洛浦县| 阿坝| 鹤岗市| 永兴县| 资阳市| 秀山|