/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="output"></param> /// <param name="Password"></param> private void Load(Stream input, Stream output, string Password) { //Release some resources: if (this._package != null) { this._package.Close(); this._package = null; } if (this._stream != null) { this._stream.Close(); this._stream.Dispose(); this._stream = null; } if (Password != null) { Stream encrStream = new MemoryStream(); CopyStream(input, ref encrStream); EncryptedPackageHandler eph = new EncryptedPackageHandler(); Encryption.Password = Password; this._stream = eph.DecryptPackage((MemoryStream)encrStream, Encryption); } else { this._stream = output; CopyStream(input, ref this._stream); } try { this._package = Package.Open(this._stream, FileMode.Open, FileAccess.ReadWrite); } catch (Exception ex) { EncryptedPackageHandler eph = new EncryptedPackageHandler(); if (Password == null && EncryptedPackageHandler.IsStorageILockBytes(eph.GetLockbyte((MemoryStream)_stream)) == 0) { throw new Exception("Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password", ex); } else { throw (ex); } } //Clear the workbook so that it gets reinitialized next time this._workbook = null; }