Os exemplos deste artigo compartilham com você o código específico para exportar dinamicamente o Excel para o zip download para Java para sua referência. O conteúdo específico é o seguinte
pacote pack.java.io.demo; importar java.io.bufferedOutputStream; importar java.io.file; importar java.io.fileInputStream; importar java.io.fileOutputStream; import java.io.ioexception; importar java.text.mimpledAformatatArtAn; Java.util.zip.zipentry; importar java.util.zip.zipOutputStream; importar jxl.workbook; importar jxl.format.alignment; import jxl.format.bolorder; import jxl.format.borderlinestyle; import jxl.format.colour; importação jxl.format.borderlinestyle; import jxl.format.colour; importação; jxl.write.label; importar jxl.write.writableCellformat; importar jxl.write.writablefont; importar jxl.write.writableSleshet; importar jxl.write.writableworkbook; import jxl.write.writeException; import jxl.write.biff.RowSexexexextEx.Rowsexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexexcex. /** * Instância de arquivo compactada ZIP * Adicionar por Zhou Haitao * @Author Administrator * */public class ZipDemo {/** * @param args * @throws ioexception * @throws writeException * @THOWSEXEXEXEXEDEDEDEXCIPCECCIONS */public static void main (string [] args) slowssexsexsexsexsexexsexexsexexexexexexcedException */public STATION Maid Main (String []) "C:/document/Excel"; // Crie uma pasta; createfile (caminho); // Crie arquivo do Excel; createexcelfile (caminho); // crie arquivo .zip; Craetezippath (caminho); // excluir todos os arquivos no diretório; Arquivo de arquivo = novo arquivo (caminho); // excluir arquivo; deleteexcelpath (arquivo); // recriar o arquivo; file.mkdirs (); } /*** Crie uma pasta; * @param caminho * @return */ public static string createfile (string path) {arquivo file = new file (caminho); // determinar se o arquivo existe; if (! file.exists ()) {// crie um arquivo; booleano bol = file.mkdirs (); if (bol) {System.out.println (caminho+"O caminho foi criado com sucesso!"); } else {System.out.println (Path+"Criação do caminho falhou!"); }} else {System.out.println (caminho+"arquivo já existe!"); } caminho de retorno; } /*** Crie arquivo Excel no diretório especificado; * @Param Path * @THOWSoxException * @Throws WriteException * @Throws RowSexEdException */public static void CreateExCelfile (String Path) lança IoException, RowSexcedEdException, WriteException {para (int i = 0; i <3; i ++) {// Crie excel; Woritableworkbook Bookbook = WorkBowsBook.CreateWorkbook (novo arquivo (Path+"/"+novo SimpleDateFormat ("yyyymmddhhmmsss"). Formato (new Date ())+"_"+(i+1)+". Xls")); // Crie o primeiro arquivo de folha; Folha de Writablletheet = Book.CreateSheet ("Arquivo de Exportação Excel", 0); // Defina a largura padrão; Sheet.getSettings (). setDefaultColumnWidth (30); // defina a fonte; WrititableFont font1 = new WrititableFont (WRIDEDFONT.ARIAL, 14, WRITEDFONT.BOLD, FALSE, Sublinkestyle.no_underline, colour.red); WritableCellFormat CellFormat1 = new WritableCellFormat (FONT1); // defina a cor do fundo; CellFormat1.setBackground (colour.blue_grey); // defina a borda; CellFormat1.setBorder (Border.all, Borderlinestyle.dash_dot); // defina o invólucro automático de linha; CellFormat1.setWrap (true); // Definir alinhamento de centralização de texto; CellFormat1.Setalignment (alinhamento.Centre); // defina centralização vertical; CellFormat1.setverticalalInel (verticalalignment.centre); //Create cell Label label1 = new Label(0, 0, "The first cell in the first row (test whether to automatically wrap it!), cellFormat1); Label label2 = new Label(1, 0, "The second cell in the first row", cellFormat1); Label label3 = new Label(2, 0, "The third cell in the first row", cellFormat1); Label label4 = new Label(3, 0, "The fourth cell in the first row", CellFormat1); WRITEDFONT (WRITEDFONT. BorderLinestyle.thin); Linha ", CellFormat2); etiqueta de etiqueta44 = nova etiqueta (3, 1," A quarta célula na segunda linha ", CellFormat2); Sheet.addcell (Label11); Sheet.addcell (Label22); Sheet.Addcell (Label33); Sheet.addcell (); / ** * GERE o arquivo .zip; = novo ZipOutputStream (New BufferOutputStream (novo FileOutputStream (File)); Excelfile.getName (); len); DeLeTeexcelPath (arquivo de arquivo) {String [] FILES = NULL; bem -sucedido! ");} else {System.out.println (" Delete falhou! ");}}} return file.delete ();}}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.