当前位置:首页 > c# ZIP压缩文件

c# ZIP压缩文件

点击次数:2781  更新日期:2019-09-26

需要引用命名空间 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);
		}
	}
	//输出到文件或网页
	....
}