public static void ViewFile(String filename) { using (Stream stream = new FileStream(filename, FileMode.Open)) { POIFSFileSystem fs = new POIFSFileSystem(stream); DisplayDirectory(fs.Root, ""); } }
/** * 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); } }
public HSSFWorkbook(POIFSFileSystem fs) : this(fs, true) { }
/// <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; }
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)) { }
/** * 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); }
public EventBasedExcelExtractor(POIFSFileSystem fs) : base(null) { this.fs = fs; }
/// <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) { }
public POIDocument(DirectoryNode dir, POIFSFileSystem fs) { this.directory = dir; //POILogFactory.GetLogger(this.GetType()); }
protected void CopyNodes(POIFSFileSystem source, POIFSFileSystem target, List<String> excepts) { POIUtils.CopyNodes(source, target, excepts); }
/// <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"); } }
/// <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); } } }
/// <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); }
/// <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) { }
/// <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 EncryptionInfo(POIFSFileSystem fs) : this(fs.Root) { }
public PropertiesOnlyDocument(POIFSFileSystem fs) : base(fs) { }
public DirectoryNode(DirectoryProperty property, POIFSFileSystem fileSystem, DirectoryNode parent) : this(property, parent, fileSystem, (NPOIFSFileSystem)null) { }
/// <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); }