public void ExportZip() { string[] fileNames = new string[] { Server.MapPath("~/products1.xlsx"), Server.MapPath("~/products2.xlsx"), Server.MapPath("~/products3.xlsx"), Server.MapPath("~/products4.xlsx"), Server.MapPath("~/products5.xlsx"), Server.MapPath("~/products6.xlsx") }; string zipPath = Server.MapPath("~/MyZip.zip"); ZipAgent zipAgent = new ZipAgent(); zipAgent.funcZipFiles(fileNames, zipPath, 8); Response.Redirect("MyZip.zip"); //FileStream fst = new FileStream(zipPath, FileMode.Open, FileAccess.Read); //byte[] byt = new byte[100000000]; //fst.Read(byt, 0, 100000000); //fst.Close(); //fst.Dispose(); //Response.Charset = "UTF-8"; //Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //Response.ContentType = "application/vnd.ms-excel"; //Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("MyZip.zip")); //Response.BinaryWrite(byt); //Response.Flush(); //Response.End(); }
//导出 public void Excel() { string[] fileNames = Directory.GetFiles(Server.MapPath("~/App_Data/")); string zipPath = Server.MapPath("~/MyZip.zip"); ZipAgent zipAgent = new ZipAgent(); zipAgent.funcZipFiles(fileNames, zipPath, 8); FileStream fst = new FileStream(zipPath, FileMode.Open, FileAccess.Read); byte[] byt = new byte[100000]; fst.Read(byt, 0, 100000); fst.Close(); fst.Dispose(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("MyZip.zip")); Response.BinaryWrite(byt); Response.Flush(); Response.End(); }