0.需要使用jxl.jar 這個包
1.頁面是
function exportcomp(meetingId){ //導入參會人員 url = '$appServer/meeting/uploadPage.htm?meetingId='+meetingId; window.open(url,'導入','status,top=250,left=300,height=200,width=500,scrollbars=yes');} <a href="javascr2.然后是上傳Excel到服務器的頁面<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>文件導入</title><link href="$appServer/CSS/main.css" rel="stylesheet" type="text/css" /><script language="Javascript"> function checkfile(){ var path = document.uploadform.path.value; if(path==''){ alert('請選擇文件'); return false; } var i = path.lastIndexOf('.'); if(path.substring(i+1,path.length)!='xls'){ alert('只能上傳excel文件'); return false; } document.getElementById('waitbar').style.display = ""; return true; } function init(){ var t='$!ms'; if(t=='Y'){ alert('導入成功!'); var url = "$appServer/meeting/meetingDetail.htm?id=$!meetingId"; window.opener.location.href=url; window.close(); } } </script></head><body onload="init()"><br /><form name="uploadform" method="post" action="$appServer/meeting/upload.htm" enctype="multipart/form-data" onsubmit="return checkfile()"><div style="margin-top:15px; margin:0 auto; width:500px;"> <fieldset style=" width:400px; padding:10px;padding-top:5px;text-align:left; border:1px solid #ae0001; "> <legend style="width:50px; color:#cb2121; font-weight:bolder; ">信息上傳</legend><div> <div class="wai"> <label for="fbwh" class="tt1 tt">請選擇附件:</label> <div class="edit_r"> <input type="file" name="path" class=" sc-td" /></div> </div> <div class="wai"></div> <table border="1" width="400" align="center" cellspacing="0" cellpadding="4" style="border-collapse: collapse" height="80"style="display:none;" id="waitbar"> <tr> <td style="font-size:12px;line-height:200%" align=center>企業導入中... <marquee style="border:1px solid #000000" direction="right" width="340" scrollamount="5" scrolldelay="10" bgcolor="#fcf5f5"> <table cellspacing="1" cellpadding="0"> <tr height=8> <td bgcolor=#3399FF width=8></td> <td></td> <td bgcolor=#3399FF width=8></td> <td></td> <td bgcolor=#3399FF width=8></td> <td></td> <td bgcolor=#3399FF width=8></td> <td></td> <td bgcolor=#3399FF width=8></td> <td></td> </tr></table></marquee></td> </tr></table></div> <div class="edit_botton"> <input type="hidden" name="meetingId" value="$!meetingId"/> <input type="submit" value="上傳"><input type="reset" value="重置"></div> </fieldset></div> </div> </fieldset></div></form></body></html>3.然后是
@RequestMapping(value = "/upload.htm") public ModelAndView upload(Long meetingId,HttpServletRequest request,Model model,UserAgent user) throws Exception { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("path"); String path=uploadService.UploadCompFile(multipartFile); List list=ExcelUtil.readexToMeetingNotice(new File(path)); for(int i=0;i<list.size();i++){ System.out.新聞熱點
疑難解答