이 기사의 예는 참조를 위해 Java에 대한 Zip Download로 Excel을 동적으로 내보내기위한 특정 코드를 공유합니다. 특정 내용은 다음과 같습니다
Package Pack.java.io.demo; import java.io.bufferedoutputStream; import java.io.file; import java.io.fileInputStream; import java.io.fileoutputStream; import java.io.ioexception; import java.text.simpledateformat; import java.date; import; java.util.zip.zipentry; import java.util.zip.zipoutputstream; import jxl.workbook; import jxl.format.alignment; import jxl.format.border import jxl.format.borderlinestyle; import jxl.format.colat. import jxl.estical ancomportlineStyle; jxl.format; jxl.write.label; import jxl.write.writablecellformat; import jxl.write.writablefont; import jxl.write.writableSheet; import jxl.write.writeworkbook; import jxl.write.write.write.biff.rowsexception; /** * ZIP 압축 파일 인스턴스 * Zhou Haitao에 의해 추가됩니다. * @author 관리자 * */public class Zipdemo {/** * @param args * @throws ioexception * @throws writeException * @throws rowsexeceedexception */public static void main (argss) rowsex rowsex, writecemence {ioExcemente {wronecement {wrowsex rowSex, ioExcemention {wrowsex rowSex. "C :/Document/Excel"; // 폴더 생성; CreateFile (경로); // Excel 파일 생성; Createexcelfile (경로); // .zip 파일 생성; Craetezippath (경로); // 디렉토리에서 모든 파일을 삭제합니다. 파일 = 새 파일 (Path); // 파일 삭제; deleteexcelpath (파일); // 파일을 재현합니다. file.mkdirs (); } /*** 폴더를 만듭니다. * @param path * @return */ public static string createFile (문자열 path) {file file = 새 파일 (path); // 파일이 존재하는지 여부를 결정합니다. if (! file.exists ()) {// 파일 생성; 부울 볼 = file.mkdirs (); if (bol) {System.out.println (Path+"Path가 성공적으로 생성되었습니다!"); } else {System.out.println (Path+"Path Creation 실패!"); }} else {system.out.println (Path+"파일이 이미 존재합니다!"); } 반환 경로; } /*** 지정된 디렉토리에서 Excel 파일을 만듭니다. * @param path * @throws ioexception * @throws writeException * @throws rowsexeceedexception */public static void createexcelfile (String Path)는 ioexception, rowsexeceededexception, writeException {(int i = 0; i <3; i ++) {// 생성 Excel; WritableWorkbook Workbook = Workbook.creatworkbook (새 파일 (path+"/"+new SimpledateFormat ( "yyyymmddhhmmss"). 형식 (new date ())+"_"+(i+1)+". xls"); // 첫 번째 시트 파일을 만듭니다. WritableSheet Sheet = Workbook.CreatESheet ( "Export Excel 파일", 0); // 기본 너비를 설정합니다. 시트 .getSettings (). setDefaultColumnWidth (30); // 글꼴을 설정합니다. WritableFont Font1 = New WritableFont (WritableFont.arial, 14, writableFont.Bold, False, Underlinestyle.no_underline, colour.red); WritableCellformat Cellformat1 = 새로운 writablecellformat (font1); // 배경색을 설정합니다. cellformat1.setbackground (colour.blue_grey); // 국경을 설정합니다. Cellformat1.SetBorder (Border.all, Borderlinestyle.dash_dot); // 자동 라인 랩 설정; cellformat1.setwrap (true); // 텍스트 센터링 정렬 설정; cellformat1.setalignment (alignment.centre); // 수직 센터링 설정; cellformat1.setverticalalignment (verticalalignment.centre); // 셀 레이블 레이블 1 = 새 레이블을 만듭니다 (0, 0, "첫 번째 행의 첫 번째 셀 (자동으로 랩핑 할 것인지 테스트하십시오!) Cellsformat1; WritableFont, 14, WritableFont.NO_BOLD, FALLE, UNDERLINESTY. Borderlinestyle. 행 ", cellformat2); 레이블 레이블 44 = 새로운 레이블 (3, 1,"두 번째 행의 네 번째 셀 ", cellformat2); sheet.addcell (label11); sheet.addcell (label22); sheet.addcell (label33); sheet.addcell (label44); // excel table; work.write (); // work.); / ** * @param path * @throws ioexcept * / public static void craetezippath (zipoutputstream ZipputStream = null) (path+new simpleddhhmmss (new Zip) ZipoutputStream (새 파일 아웃 푸트 스트림 (파일)). excelfile.getName ()는 ZipoutPutStream을 넣습니다. // close; ZipputStream.closeEntry (fileInputStream.close ()} {ZipOutputStream! file = null (file! = null) {file = file.list (); System.out.println ( "삭제 실패!")} return file.delete ()};위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.