예제 #1
0
        internal void Save(MemoryStream ms)
        {
            var doc = new CompoundDocumentFile();

            WriteStorageAndStreams(Storage, doc.RootItem);
            doc.Write(ms);
        }
예제 #2
0
 internal void Read(MemoryStream ms)
 {
     using (var doc = new CompoundDocumentFile(ms))
     {
         Storage = new StoragePart();
         GetStorageAndStreams(Storage, doc.RootItem);
     }
 }
예제 #3
0
        public void ReadEncLong()
        {
            var doc = File.ReadAllBytes(@"c:\temp\EncrDocRead.xlsx");
            var cd  = new CompoundDocumentFile(doc);
            var ms  = new MemoryStream();

            cd.Write(ms);

            File.WriteAllBytes(@"c:\temp\vba.xlsx", ms.ToArray());
        }
예제 #4
0
        public void Read()
        {
            //var doc = File.ReadAllBytes(@"c:\temp\vbaProject.bin");
            var doc = File.ReadAllBytes(@"c:\temp\vba.bin");
            var cd  = new CompoundDocumentFile(doc);
            var ms  = new MemoryStream();

            cd.Write(ms);
            printitems(cd.RootItem);
            File.WriteAllBytes(@"c:\temp\vba.bin", ms.ToArray());
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="Password"></param>
        /// <param name="cancellationToken"></param>
        private async Task LoadAsync(Stream input, Stream output, string Password, CancellationToken cancellationToken)
        {
            ReleaseResources();
            if (input.CanSeek && input.Length == 0) // Template is blank, Construct new
            {
                _stream = output;
                await ConstructNewFileAsync(Password, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                Stream ms;
                _stream = output;
                if (Password != null)
                {
                    using (var encrStream = RecyclableMemory.GetStream())
                    {
                        await CopyStreamAsync(input, encrStream, cancellationToken).ConfigureAwait(false);

                        var eph = new EncryptedPackageHandler();
                        Encryption.Password = Password;
                        ms = eph.DecryptPackage(encrStream, Encryption);
                    }
                }
                else
                {
                    ms = RecyclableMemory.GetStream();
                    await CopyStreamAsync(input, ms, cancellationToken).ConfigureAwait(false);
                }

                try
                {
                    _zipPackage = new Packaging.ZipPackage(ms);
                }
                catch (Exception ex)
                {
                    if (Password == null && await CompoundDocumentFile.IsCompoundDocumentAsync((MemoryStream)_stream, cancellationToken).ConfigureAwait(false))
                    {
                        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);
                    }

                    throw;
                }
                finally
                {
                    ms.Dispose();
                }
            }
            //Clear the workbook so that it gets reinitialized next time
            this._workbook = null;
        }
예제 #6
0
        private async Task ConstructNewFileAsync(string password)
        {
            var ms = new MemoryStream();

            if (_stream == null)
            {
                _stream = new MemoryStream();
            }
            if (File != null)
            {
                File.Refresh();
            }
            if (File != null && File.Exists)
            {
                if (password != null)
                {
                    var encrHandler = new EncryptedPackageHandler();
                    Encryption.IsEncrypted = true;
                    Encryption.Password    = password;
                    ms          = encrHandler.DecryptPackage(File, Encryption);
                    encrHandler = null;
                }
                else
                {
                    await WriteFileToStreamAsync(File.FullName, ms);
                }
                try
                {
                    _package = new Packaging.ZipPackage(ms);
                }
                catch (Exception ex)
                {
                    if (password == null && await CompoundDocumentFile.IsCompoundDocumentAsync(File).ConfigureAwait(false))
                    {
                        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;
                    }
                }
            }
            else
            {
                _package = new Packaging.ZipPackage(ms);
                CreateBlankWb();
            }
        }
예제 #7
0
 internal static bool IsCompoundDocument(MemoryStream ms)
 {
     return(CompoundDocumentFile.IsCompoundDocument(ms));
 }
예제 #8
0
 internal static bool IsCompoundDocument(FileInfo fi)
 {
     return(CompoundDocumentFile.IsCompoundDocument(fi));
 }