Example #1
0
 public static void ViewFile(String filename)
 {
     using (Stream stream = new FileStream(filename, FileMode.Open))
     {
         POIFSFileSystem fs = new POIFSFileSystem(stream);
         DisplayDirectory(fs.Root, "");
     }
 }
Example #2
0
        /**
         * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
         * to include a stream "{01}Ole10Native" which Contains the actual
         * data relevant for this class.
         *
         * @param poifs POI Filesystem object
         * @return Returns an instance of this class
         * @throws IOException on IO error
         * @throws Ole10NativeException on invalid or unexcepted data format
         */
        public static Ole10Native CreateFromEmbeddedOleObject(POIFSFileSystem poifs)
        {
            bool plain = false;

            try
            {
                poifs.Root.GetEntry("\x0001Ole10ItemName");             
                plain = true;
            }
            catch (FileNotFoundException)
            {
                plain = false;
            }

            DocumentInputStream dis = poifs.CreateDocumentInputStream(OLE10_NATIVE);
            using (MemoryStream bos = new MemoryStream())
            {
                IOUtils.Copy(dis, bos);
                byte[] data = bos.ToArray();

                return new Ole10Native(data, 0, plain);
            }
        }
Example #3
0
        public HSSFWorkbook(POIFSFileSystem fs)
            : this(fs, true)
        {

        }
Example #4
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;
        }
Example #5
0
 public Stream GetDataStream(POIFSFileSystem fs)
 {
     return GetDataStream(fs.Root);
 }
 /// <summary>
 /// Processes a file into essentially record events.
 /// </summary>
 /// <param name="req">an Instance of HSSFRequest which has your registered listeners</param>
 /// <param name="fs">a POIFS filesystem containing your workbook</param>
 /// <returns>numeric user-specified result code.</returns>
 public short AbortableProcessWorkbookEvents(HSSFRequest req, POIFSFileSystem fs)
 {
     Stream in1 = fs.CreateDocumentInputStream("Workbook");
     return AbortableProcessEvents(req, in1);
 }
        public HPSFPropertiesExtractor(POIFSFileSystem fs)
            : base(new PropertiesOnlyDocument(fs))
        {

        }
Example #8
0
 /**
  * Copies nodes from one POIFS to the other minus the excepts
  * 
  * @param source
  *            is the source POIFS to copy from
  * @param target
  *            is the target POIFS to copy to
  * @param excepts
  *            is a list of Strings specifying what nodes NOT to copy
  */
 public static void CopyNodes(POIFSFileSystem source,
         POIFSFileSystem target, List<String> excepts)
 {
     // System.err.println("CopyNodes called");
     CopyNodes(source.Root, target.Root, excepts);
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="POIDocument"/> class.
 /// </summary>
 /// <param name="fs">The fs.</param>
 public POIDocument(POIFSFileSystem fs)
     : this(fs.Root) 
 {
     
 }
Example #10
0
 public POIDocument(DirectoryNode dir, POIFSFileSystem fs)
 {
     this.directory = dir;
     //POILogFactory.GetLogger(this.GetType());
 }
Example #11
0
 protected void CopyNodes(POIFSFileSystem source, POIFSFileSystem target,
                           List<String> excepts)
 {
     POIUtils.CopyNodes(source, target, excepts);
 }
Example #12
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");
     }
 }
Example #13
0
 /// <summary>
 /// Writes out the standard Documment Information Properties (HPSF)
 /// </summary>
 /// <param name="outFS">the POIFSFileSystem to Write the properties into.</param>
 /// <param name="writtenEntries">a list of POIFS entries to Add the property names too.</param>
 protected void WriteProperties(POIFSFileSystem outFS, IList writtenEntries)
 {
     if (sInf != null)
     {
         WritePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, sInf, outFS);
         if (writtenEntries != null)
         {
             writtenEntries.Add(SummaryInformation.DEFAULT_STREAM_NAME);
         }
     }
     if (dsInf != null)
     {
         WritePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME, dsInf, outFS);
         if (writtenEntries != null)
         {
             writtenEntries.Add(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
         }
     }
 }
Example #14
0
 /// <summary>
 /// Writes out the standard Documment Information Properties (HPSF)
 /// </summary>
 /// <param name="outFS">the POIFSFileSystem to Write the properties into</param>
 protected void WriteProperties(POIFSFileSystem outFS)
 {
     WriteProperties(outFS, null);
 }
Example #15
0
        /// <summary>
        /// given a POI POIFSFileSystem object, Read in its Workbook and populate the high and
        /// low level models.  If you're Reading in a workbook...start here.
        /// </summary>
        /// <param name="fs">the POI filesystem that Contains the Workbook stream.</param>
        /// <param name="preserveNodes">whether to preseve other nodes, such as
        /// macros.  This takes more memory, so only say yes if you
        /// need to. If Set, will store all of the POIFSFileSystem
        /// in memory</param>
        public HSSFWorkbook(POIFSFileSystem fs, bool preserveNodes)
            : this(fs.Root, fs, preserveNodes)
        {

        }
Example #16
0
 /// <summary>
 /// given a POI POIFSFileSystem object, and a specific directory
 /// within it, Read in its Workbook and populate the high and
 /// low level models.  If you're Reading in a workbook...start here.
 /// </summary>
 /// <param name="directory">the POI filesystem directory to Process from</param>
 /// <param name="fs">the POI filesystem that Contains the Workbook stream.</param>
 /// <param name="preserveNodes">whether to preseve other nodes, such as
 /// macros.  This takes more memory, so only say yes if you
 /// need to. If Set, will store all of the POIFSFileSystem
 /// in memory</param>
 public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, bool preserveNodes)
     : this(directory, preserveNodes)
 {
 }
        public EventBasedExcelExtractor(POIFSFileSystem fs)
            : base(null)
        {

            this.fs = fs;
        }
            public PropertiesOnlyDocument(POIFSFileSystem fs)
                : base(fs)
            {

            }
 public EncryptionInfo(POIFSFileSystem fs)
     : this(fs.Root)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExcelExtractor"/> class.
 /// </summary>
 /// <param name="fs">The fs.</param>
 public ExcelExtractor(POIFSFileSystem fs)
     : this(new HSSFWorkbook(fs))
 {
 }
        /// <summary>
        /// Processes a file into essentially record events.
        /// </summary>
        /// <param name="req">an Instance of HSSFRequest which has your registered listeners</param>
        /// <param name="fs">a POIFS filesystem containing your workbook</param>
        public void ProcessWorkbookEvents(HSSFRequest req, POIFSFileSystem fs)
        {
            Stream in1 = fs.CreateDocumentInputStream("Workbook");

            ProcessEvents(req, in1);
        }