/** * Read all files from a POI filesystem which are property Set streams * and returns them as an array of {@link org.apache.poi.hpsf.PropertySet} * instances. * * @param poiFs The name of the POI filesystem as seen by the * operating system. (This is the "filename".) * * @return The property Sets. The elements are ordered in the same way * as the files in the POI filesystem. * * @exception FileNotFoundException if the file containing the POI * filesystem does not exist * * @exception IOException if an I/O exception occurs */ public static POIFile[] ReadPropertySets(FileInfo poifs) { List <POIFile> files = new List <POIFile>(7); POIFSReader reader2 = new POIFSReader(); //reader2.StreamReaded += new POIFSReaderEventHandler(reader2_StreamReaded); POIFSReaderListener pfl = new POIFSReaderListener1(files); reader2.RegisterListener(pfl); /* Read the POI filesystem. */ FileStream stream = poifs.OpenRead(); try { reader2.Read(stream); } finally { stream.Close(); } POIFile[] result = new POIFile[files.Count]; for (int i = 0; i < result.Length; i++) { result[i] = files[i]; } return(result); }
public void TestWriteSimplePropertySet() { String AUTHOR = "Rainer Klute"; String TITLE = "Test Document"; FileInfo fi = TempFile.CreateTempFile(POI_FS, ".doc"); FileStream file = new FileStream(fi.FullName, FileMode.Open, FileAccess.ReadWrite); FileStream out1 = file; POIFSFileSystem poiFs = new POIFSFileSystem(); MutablePropertySet ps = new MutablePropertySet(); MutableSection si = new MutableSection(); si.SetFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); ps.Sections[0] = si; MutableProperty p = new MutableProperty(); p.ID = PropertyIDMap.PID_AUTHOR; p.Type = Variant.VT_LPWSTR; p.Value = AUTHOR; si.SetProperty(p); si.SetProperty(PropertyIDMap.PID_TITLE, Variant.VT_LPSTR, TITLE); poiFs.CreateDocument(ps.ToInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); poiFs.WriteFileSystem(out1); poiFs.Close(); //out1.Close(); file.Position = 0; POIFSReader reader1 = new POIFSReader(); //reader1.StreamReaded += new POIFSReaderEventHandler(reader1_StreamReaded); POIFSReaderListener1 psl = new POIFSReaderListener1(); reader1.RegisterListener(psl); reader1.Read(file); Assert.IsNotNull(psa[0]); Assert.IsTrue(psa[0].IsSummaryInformation); Section s = (Section)(psa[0].Sections[0]); Object p1 = s.GetProperty(PropertyIDMap.PID_AUTHOR); Object p2 = s.GetProperty(PropertyIDMap.PID_TITLE); Assert.AreEqual(AUTHOR, p1); Assert.AreEqual(TITLE, p2); file.Close(); try { File.Delete(fi.FullName); } catch { } }
/** * Read all files from a POI filesystem which are property Set streams * and returns them as an array of {@link org.apache.poi.hpsf.PropertySet} * instances. * * @param poiFs The name of the POI filesystem as seen by the * operating system. (This is the "filename".) * * @return The property Sets. The elements are ordered in the same way * as the files in the POI filesystem. * * @exception FileNotFoundException if the file containing the POI * filesystem does not exist * * @exception IOException if an I/O exception occurs */ public static POIFile[] ReadPropertySets(FileStream poifs) { files = new ArrayList(7); POIFSReader reader2 = new POIFSReader(); //reader2.StreamReaded += new POIFSReaderEventHandler(reader2_StreamReaded); POIFSReaderListener pfl = new POIFSReaderListener1(); reader2.RegisterListener(pfl); /* Read the POI filesystem. */ reader2.Read(poifs); POIFile[] result = new POIFile[files.Count]; for (int i = 0; i < result.Length; i++) { result[i] = (POIFile)files[i]; } return(result); }
/** * Read all files from a POI filesystem which are property Set streams * and returns them as an array of {@link org.apache.poi.hpsf.PropertySet} * instances. * * @param poiFs The name of the POI filesystem as seen by the * operating system. (This is the "filename".) * * @return The property Sets. The elements are ordered in the same way * as the files in the POI filesystem. * * @exception FileNotFoundException if the file containing the POI * filesystem does not exist * * @exception IOException if an I/O exception occurs */ public static POIFile[] ReadPropertySets(FileStream poifs) { files = new ArrayList(7); POIFSReader reader2 = new POIFSReader(); //reader2.StreamReaded += new POIFSReaderEventHandler(reader2_StreamReaded); POIFSReaderListener pfl = new POIFSReaderListener1(); reader2.RegisterListener(pfl); /* Read the POI filesystem. */ reader2.Read(poifs); POIFile[] result = new POIFile[files.Count]; for (int i = 0; i < result.Length; i++) result[i] = (POIFile)files[i]; return result; }
public void TestWriteSimplePropertySet() { String AUTHOR = "Rainer Klute"; String TITLE = "Test Document"; FileInfo fi = TempFile.CreateTempFile(POI_FS, ".doc"); FileStream file = new FileStream(fi.FullName, FileMode.Open, FileAccess.ReadWrite); FileStream out1 = file; POIFSFileSystem poiFs = new POIFSFileSystem(); MutablePropertySet ps = new MutablePropertySet(); MutableSection si = new MutableSection(); si.SetFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); ps.Sections[0] = si; MutableProperty p = new MutableProperty(); p.ID = PropertyIDMap.PID_AUTHOR; p.Type = Variant.VT_LPWSTR; p.Value = AUTHOR; si.SetProperty(p); si.SetProperty(PropertyIDMap.PID_TITLE, Variant.VT_LPSTR, TITLE); poiFs.CreateDocument(ps.GetStream(), SummaryInformation.DEFAULT_STREAM_NAME); poiFs.WriteFileSystem(out1); //out1.Close(); file.Position = 0; POIFSReader reader1 = new POIFSReader(); //reader1.StreamReaded += new POIFSReaderEventHandler(reader1_StreamReaded); POIFSReaderListener1 psl = new POIFSReaderListener1(); reader1.RegisterListener(psl); reader1.Read(file); Assert.IsNotNull(psa[0]); Assert.IsTrue(psa[0].IsSummaryInformation); Section s = (Section)(psa[0].Sections[0]); Object p1 = s.GetProperty(PropertyIDMap.PID_AUTHOR); Object p2 = s.GetProperty(PropertyIDMap.PID_TITLE); Assert.AreEqual(AUTHOR, p1); Assert.AreEqual(TITLE, p2); file.Close(); try { File.Delete(fi.FullName); } catch { } }