Ejemplo n.º 1
0
 /// <summary>
 /// Writes out a given ProperySet
 /// </summary>
 /// <param name="name">the (POIFS Level) name of the property to Write.</param>
 /// <param name="Set">the PropertySet to Write out.</param>
 /// <param name="outFS">the POIFSFileSystem to Write the property into.</param>
 protected void WritePropertySet(String name, PropertySet Set, POIFSFileSystem outFS)
 {
     try
     {
         MutablePropertySet mSet = new MutablePropertySet(Set);
         using (MemoryStream bOut = new MemoryStream())
         {
             mSet.Write(bOut);
             byte[] data = bOut.ToArray();
             using (MemoryStream bIn = new MemoryStream(data))
             {
                 outFS.CreateDocument(bIn, name);
             }
             //logger.Log(POILogger.INFO, "Wrote property Set " + name + " of size " + data.Length);
         }
     }
     catch (WritingNotSupportedException)
     {
         Console.Error.WriteLine("Couldn't Write property Set with name " + name + " as not supported by HPSF yet");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Write out this workbook to an Outputstream.  Constructs
        /// a new POI POIFSFileSystem, passes in the workbook binary representation  and
        /// Writes it out.
        /// </summary>
        /// <param name="stream">the java OutputStream you wish to Write the XLS to</param>
        public override void Write(Stream stream)
        {
            byte[] bytes = GetBytes();
            POIFSFileSystem fs = new POIFSFileSystem();
            
            // For tracking what we've written out, used if we're
            //  going to be preserving nodes
            List<string> excepts = new List<string>(1);

            using (MemoryStream newMemoryStream = new MemoryStream(bytes))
            {
                // Write out the Workbook stream
                fs.CreateDocument(newMemoryStream, "Workbook");

                // Write out our HPFS properties, if we have them
                WriteProperties(fs, excepts);

                if (preserveNodes)
                {
                    // Don't Write out the old Workbook, we'll be doing our new one
                    excepts.Add("Workbook");
                    // If the file had WORKBOOK instead of Workbook, we'll Write it
                    //  out correctly shortly, so don't include the old one
                    excepts.Add("WORKBOOK");

                    // Copy over all the other nodes to our new poifs
                    POIUtils.CopyNodes(directory, fs.Root, excepts);
                    // YK: preserve StorageClsid, it is important for embedded workbooks,
                    // see Bugzilla 47920
                    fs.Root.StorageClsid = (this.directory.StorageClsid);
                }
                fs.WriteFileSystem(stream);

            }
            
            bytes = null;
        }