예제 #1
0
 private static void InitializeXlsFile(CompoundFile xlsFile)
 {
     if (xlsFile == null)
     {
         throw new ArgumentNullException();
     }
     xlsFile.AddStream(XlsDirectoryEntryNames.SummaryInformationStream, new byte[0x40]);
     xlsFile.AddStream(XlsDirectoryEntryNames.DocumentSummaryInfomationStream, new byte[0x40]);
 }
        /// <summary>
        /// Gets a child stream by its name or create a new one if not found.
        /// </summary>
        /// <param name="name">The name. May not be null.</param>
        /// <returns>
        /// An instance of the CompoundFileStream class.
        /// </returns>
        public CompoundFileStream GetOrAddChildStream(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var stream = GetChildStream(name);

            if (stream != null)
            {
                return(stream);
            }

            stream = _file.AddStream(this, name);
            _streams.Add(stream);
            return(stream);
        }
예제 #3
0
 private void SaveToCompoundStorage(Stream fileStream, string password)
 {
     if (fileStream != null)
     {
         BiffRecordWriter writer = null;
         MemoryStream     stream = new MemoryStream();
         writer = new BiffRecordWriter(this._excelWriter, this._measure);
         if (((password != null) && (password.Length > 0)) && (password.Length < 0x100))
         {
             writer.IsEncrypted = true;
         }
         writer.BuildStream((Stream)stream);
         CompoundFile xlsFile = new CompoundFile(false);
         InitializeXlsFile(xlsFile);
         xlsFile.AddStream(XlsDirectoryEntryNames.WorkbookStream, stream.ToArray());
         xlsFile.Write(fileStream);
     }
 }