需要引用命名空间 System.IO.Compression
using (MemoryStream ms = new MemoryStream()) { using (ZipArchive zipArchive = new ZipArchive(ms, ZipArchiveMode.Create, true)) { //添加文件 ZipArchiveEntry entry = zipArchive.CreateEntry("abc1.xlsx"); using (Stream stream = entry.Open()) { byte[] excelBytes = exportor.GetBytes(); stream.Write(excelBytes, 0, excelBytes.Length); } } //输出到文件或网页 .... }