1. 프로젝트에 내보내기 로그 정보를 추가하십시오
2. 프로젝트에서 poi-*. jar와 같은 Excel 파일을 작동하는 JAR 파일 가져 오기
Excel Export는 포 그라운드 조건에 따라 매개 변수를 컨트롤러로 전달하고 매개 변수에 따라 데이터베이스를 쿼리하고 목록 수집을 쿼리하며 엑시클 데이터를 생성하여 목록 수집을 다운로드하는 것입니다.
코드 스 니펫 :
Contorller.java
/*** 내보내기 정보* @param model*/@requestmapping ( "ExportCustomer.do") @systemControllerLog (description = "database form exportexcle") public void ExportCustomer (ModelMap Model) {// todo 조건을 추가 해야하는 경우 //model.AdDattRibute (이것은 NAMETRIME); // 데이터를 내보내도록 목록 목록 목록 <CMCUSTOMER> CUSLIST = customerService.exportCustomer (Model); //이 메소드를 사용하여 Excle Template 스타일을 생성합니다 HSSFWorkbook Workbook = CustomersIrvice.createexcel (Cuslist, request); simpledateformat 형식 = 새로운 simpledateformat ( "yyyymmddhhmmss"); // 파일 이름 형식 정의 try {// excle 이름을 정의하여 grabled 문자열 msg = new String (( "customer information_" + format.format (new date ()) + ".xls"). getBytes (), "ISO-8859-1"); // 내보내기 시간을 파일 이름으로 사용합니다. response.addheader ( "Content-Disposition", "첨부 파일; filename =" + msg); workbook.write (response.getoutPutStream ()); } catch (ioexception e) {logger.error (e); }} 2. Createexcel 서비스 중입니다
public hssfworkbook createexcel (list <cmcustomer> cuslist, httpservletrequest request) {// excel 파일에 해당하는 웹 북 만들기 hssfworkbook workbook = new hssfworkbook (); // 엑셀 파일의 시트에 해당하는 웹 북에 시트를 추가합니다. // 열 너비 시트를 설정합니다. SETER.SETCOLUMNWIDTH (1, 35 * 100); SETHE.SETCOLUMNWIDTH (2, 35 * 100); SETER.SETCOLUMNWIDTH (3, 40 * 100); SETER.SETCOLUMNWIDTH (4, 45 * 100); SETER.SETCOLUMNWIDTH (5, 45 * 100); SETER.SETCOLUMNWIDTH (6, 50 * 100); SETER.SETCOLUMNWIDTH (7, 80 * 100); SETER.SETCOLUMNWIDTH (8, 35 * 100); SETHE.SETCOLUMNWIDTH (9, 40 * 100); // 시트에 헤더의 행 0을 추가합니다. hssfrow row = sheet.createrow (0); // 셀을 만들고 테이블 헤더를 설정하고 테이블 헤더를 중앙으로 설정합니다. // 중앙 형식 스타일을 만듭니다 .setalignment (hssfcellstyle.align_center); // Border Style.setborderbottom (hssfcellstyle.border_thin); // 글꼴 생성 hssffont font = workbook.createFont (); // 글꼴 두꺼운 font.setboldweight (hssffont.boldweight_bold); // font size font.setfontheightinpoints ((짧은) 12); // 글꼴을 현재 스타일 스타일에 적용합니다. // 전체 열을 중앙으로 설정하거나 별도로 왼쪽으로 설정합니다. Style1.setalignment (hssfcellstyle.align_center); hssfcellstyle style2 = workbook.createcellstyle (); style2.setalignment (hssfcellstyle.align_left); hssfcellstyle style3 = workbook.createcellstyle (); style3.setalignment (hssfcellstyle.align_left); hssffont hsffont = workbook.createfont (); hssffont.setcolor (hssffont.color_red); hssffont.setboldweight (hssffont.boldweight_bold); style3.setfont (hssffont); hssfcellstyle style4 = workbook.createcellstyle (); style4.setalignment (hssfcellstyle.align_left); hssffont hsffont1 = workbook.createfont (); hssffont1.setcolor (hssffont.color_normal); hssffont1.setboldweight (hssffont.boldweight_bold); style4.setfont (hssffont1); hssfcell cell = row.createcell (0); cell.setCellValue ( "일련 번호"); Cell.setCellStyle (스타일); cell = row.createcell (1); cell.setCellValue ( "고객 이름"); Cell.setCellStyle (스타일); cell = row.createcell (2); cell.setCellValue ( "성별"); Cell.setCellStyle (스타일); cell = row.createcell (3); cell.setCellValue ( "상태"); Cell.setCellStyle (스타일); cell = row.createcell (4); cell.setCellValue ( "전화"); Cell.setCellStyle (스타일); cell = row.createcell (5); Cell.setCellValue ( "MailBox"); Cell.setCellStyle (스타일); cell = row.createcell (6); cell.setCellValue ( "주소"); Cell.setCellStyle (스타일); for (int i = 0; i <cuslist.size (); i ++) {String logtypedis = ""; row = sheet.createrow (i + 1); cmcustomer cmcustomer = cuslist.get (i); // 셀을 생성하고 값을 설정 // 번호가 매겨진 열은 왼쪽에 있습니다 hssfcell c1 = row.createcell (0); C1.SetCellStyle (Style2); C1.SetCellValue (I); hssfcell c2 = row.createcell (1); C2.SetCellStyle (Style1); c2.setCellValue (cmcustomer.getCustomerName ()); // 고객 이름 문자열 sexstr = cmcustomer.getSex (); // gender 0 : 여자, 1 : 남성 문자열 sex = ""; if ( "1".equals (sexstr)) {sex = "male"; } if ( "0".equals (sexstr)) {sex = "여성"; } hssfcell c3 = row.createcell (2); // gender c3. setcellstyle (style1); C3. 세트 셀 value (섹스); 문자열 statusStr = cmcustomer.getStatus (); // 고객 상태 1. on-the-job, 2. left string status = ""; if ( "1".equals (statusst)) {status = "on-the-job"; } if ( "2".Equals (statusStr)) {status = "riSign"; } hssfcell c4 = row.createcell (3); // status c4. setcellstyle (style1); c4. 세트 셀 value (상태); 문자열 customerID = cmcustomer.getCustomerId (); // 고객 ID 목록 <CMPhone> phonElist = cmphonemapper.selectByCustomErid (customerID); 문자열 phone = ""; if (phonelist! = null && phonelist.size ()> 0) {for (int j = 0; }} hssfcell c5 = row.createcell (4); // telect c5. setcellstyle (style1); C5. 세트 셀 value (전화); 목록 <cmemail> emaillist = cmemailmapper.selectall (customerId); 문자열 이메일 = ""; if (emaillist! = null && emaillist.size ()> 0) {for (int j = 0; j <emaillist.size (); j ++) {email = emaillist.get (j) .getemail (); }} hssfcell c6 = row.createcell (5); // emailbox c6.setcellstyle (style1); C6. SetCellValue (이메일); CMADDRESS CMADDRESS = NEW CMADDRESS (); cmaddress.setCustomerId (customerID); <cmaddress> addersslist = cmaddressmapper.selectall (cmaddress); 문자열 adderss = ""; if (addersslist! = null && addersslist.size ()> 0) {for (int j = 0; j <addersslist.size (); j ++) {adderss = addersslist.get (j) .getAddress (); }} hssfcell c7 = row.createcell (6); // 주소 c7.setcellstyle (style1); C7. SetCellValue (Adderss); // 기본 형식을 사용합니다. row.createcell (2) .SetCellValue (섹스); row.createCell (3) .SetCellValue (상태); row.createcell (4) .SetCellValue (전화); row.createcell (5) .SetCellValue (이메일); row.createcell (6) .SetCellValue (adderss); } 반환 통합 문서; } 3. 페이지 JSP 호출
// 내보내기 정보 함수 EXPORBTN () {$ .ajax ({type : "post", url : "<%= path%>/customer/exportCustomer.do", success : function (data) {window.open ( '<%= path%>/customer/exportCustomer.do');}); }위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.