Vb.net 如何压缩Excel文件?

Vb.net 如何压缩Excel文件?,vb.net,Vb.net,我一直在试图弄明白如何压缩一个Excel.Xlsm文件,但运气不好。下面的代码创建了zip文件,但我不知道如何将.xlsm文件发送到它。感谢您的帮助 Dim zipPath As String=RegScoringWorkbookName.Replace(“.xlsm”,“.zip”)”从.xlsm文件创建zip文件 尝试 如果File.Exists(zipPath)存在,则 My.Computer.FileSystem.DeleteFile(zipPath、FileIO.UIOption.On

我一直在试图弄明白如何压缩一个Excel.Xlsm文件,但运气不好。下面的代码创建了zip文件,但我不知道如何将.xlsm文件发送到它。感谢您的帮助

Dim zipPath As String=RegScoringWorkbookName.Replace(“.xlsm”,“.zip”)”从.xlsm文件创建zip文件
尝试
如果File.Exists(zipPath)存在,则
My.Computer.FileSystem.DeleteFile(zipPath、FileIO.UIOption.OnlyErrorDialogs、,
FileIO.RecycleOption.DeletePermanently)
如果结束
Dim FilePath为String=RegScoringWorkbookName'的.xlsm文件路径
使用FileStream=newfilestream(zipPath,FileMode.CreateNew)
使用archive=New ZipArchive(FileStream,ZipArchiveMode.Create,True)
Dim zipArchiveEntry=archive.CreateEntry(GetFileName(FilePath),CompressionLevel.Optimal)
使用zipStream=zipArchiveEntry.Open()
'zipStream.WriteAsync()
zipStream.Close()
终端使用
终端使用
终端使用
特例
结束尝试

我将在这里引用MSDN代码,因为这里有一个确切的例子。

Imports System.IO
导入System.IO压缩
模块1
副标题()
Dim zipPath As String=“c:\users\exampleuser\end.zip”
Dim extractPath为String=“c:\users\exampleuser\extract”
Dim newFile As String=“c:\users\exampleuser\newFile.txt”
使用归档文件作为ZipArchive=ZipFile.Open(zipPath,ZipArchiveMode.Create)将其更改为从MSDN创建
archive.CreateEntryFromFile(newFile,“NewEntry.txt”,CompressionLevel.faster)
终端使用
端接头
端模块

这应该是不言自明的。此时无需使用filestream,因为有一种预先制作的方法来压缩现有文件,
CreateEntryFromFile

这是如何特定于Excel文件的?这就解决了Jens的问题。我搜索了这个msdn示例,但从未遇到过。