Los ejemplos en este artículo comparten con usted el código específico para exportar dinámicamente Excel a descargar zip para Java para su referencia. El contenido específico es el siguiente
paquete paquete.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.util.date; importar; import java.util.zip.zipEntry; import java.util.zip.zipoutputStream; import jxl.workbook; import jxl.format.alignment; import jxl.format.border; import jxl.format.borderlinlinyyle; import jxl.format.colour; import jxl.Format.underlinestyle; jxl.write.label; import jxl.Write.WritableCellFormat; import jxl.write.writablefont; import jxl.write.writableSheetet; import jxl.Write.WritingWorkbook; import jxl.write.writeException; import jxl.write.biff.rowsexceedException; /** * Instancia de archivo comprimido zip * agregue por zhou haitao * @author administrador * */public class ZipDemo {/** * @param args * @throws ioexception * @throws writeException * @throws rowsexceedException */public static main (string [] args) lanza Rowsexception, writException, Ioxception {string string [] args) lanzada "C:/documento/Excel"; // crear una carpeta; createFile (ruta); // Crear archivo Excel; createExcelfile (ruta); // Crear archivo .zip; craetezippath (camino); // eliminar todos los archivos en el directorio; Archivo archivo = nuevo archivo (ruta); // Eliminar archivo; DeleteExcelpath (archivo); // recrea el archivo; file.mkdirs (); } /*** Crear una carpeta; * @param ruta * @return */ public static string createFile (string path) {archivo file = new File (ruta); // determinar si el archivo existe; if (! file.exists ()) {// crea un archivo; boolean bol = file.mkdirs (); if (bol) {system.out.println (ruta+"La ruta se creó con éxito!"); } else {System.out.println (ruta+"¡Falló la creación de la ruta!"); }} else {System.out.println (Path+"El archivo ya existe!"); } ruta de retorno; } /*** Crear archivo Excel en el directorio especificado; * @param ruta * @throws ioException * @throws writeException * @throws rowsexceedException */public static void createExcEffile (string ruta) lanza ioexception, rowsexceedException, writeException {for (int i = 0; i <3; i ++) {// create Excel; WRATITYWORKBOOK Workbook = Workbook.CreAteWorkBook (nuevo archivo (ruta+"/"+nuevo SimpledateFormat ("yyyyMMDDHHMMSSS"). Format (new Date ())+"_"+(i+1)+". XLS")); // Crear el primer archivo de hoja; WRITABLESHEET SHOET = Workbook.CreateSheet ("Exportar archivo Excel", 0); // Establecer el ancho predeterminado; sheet.getSettings (). setDefaultColumnWidth (30); // Establecer la fuente; WATITYFONT FONT1 = New WittitionFont (WRITITYFONT.Arial, 14, WittitingFont.Bold, False, Underlinestyle.no_underline, Colour.Red); WRITABLECELLFORMAT CELLFORMAT1 = new WriteableCellFormat (font1); // Establecer el color de fondo; CellFormat1.SetBackground (color.blue_grey); // establecer el borde; CellFormat1.setBorder (Border.all, BorderLinestyle.Dash_Dot); // Establecer una envoltura de línea automática; CellFormat1.SetWrap (True); // Establecer alineación de centrado de texto; CellFormat1.setalignment (alineación.centre); // establecer centrado vertical; CellFormat1.SetVerticalAlignment (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) WATITYFONT (WRATITYFONT.ARIAL, 14, WRITITYFONT.NO_BOLS, FALSO, UNTLINETYLE. BorderLinestyle.thin); fila ", celleFormat2); etiqueta etiqueta44 = nueva etiqueta (3, 1," la cuarta celda en la segunda fila ", celleFormat2); shead.addcell (etiqueta11); shead.addcell (etiqueta22); shead.addcell (etiqueta33); shead.addcell (etiqueta44); // escritura a excel / ** * Generar el archivo .zip; = nuevo ZipOutputStream (nuevo BuffeDoutputStream (nuevo FileOtputStream (archivo)); Excelfile.getName (); Len); DeleteExcelpath (archivo de archivo) {string [] files = null; System.out.println ("¡Eliminar exitoso!");Lo anterior es todo el contenido de este artículo. Espero que sea útil para el aprendizaje de todos y espero que todos apoyen más a Wulin.com.