我使用以下代码打开一个excel文件:
Private EPXlApp As OfficeOpenXml.ExcelPackage
Private EPXlFile As FileInfo
Private EPXlSheet As ExcelWorksheet
Private EPXlWorkbook As ExcelWorkbook
Public Sub New(newFilePath As String, Optional password As String = "")
PathFile = newFilePath
OfficeOpenXml.ExcelPackage.LicenseContext = LicenseContext.NonCommercial
EPXlFile = New FileInfo(PathFile)
EPXlApp = New OfficeOpenXml.ExcelPackage(EPXlFile, password) ' ---> here the error occurs
EPXlWorkbook = EPXlApp.Workbook
EPXlSheet = EPXlApp.Workbook.Worksheets(1)
End sub
这有效。但是,如果有人阻止了该文件,我将无法再次打开它。我不明白错误消息
System.IO.InvalidDataException:“文件S:\ Team \ file.xlsm不是加密的程序包”
因为那是rigt密码,所以如果没有人阻止excel文件,它已经起作用。
非常感谢您!