public void TestRecord()
        {
            POIFSFileSystem fs = new POIFSFileSystem(
                HSSFTestDataSamples.OpenSampleFileStream("WithFormattedGraphTitle.xls"));

            // Check we can Open the file via usermodel
            HSSFWorkbook hssf = new HSSFWorkbook(fs);

            // Now process it through eventusermodel, and
            //  look out for the title records
            ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
            Stream      din = fs.CreatePOIFSDocumentReader("Workbook");
            HSSFRequest req = new HSSFRequest();

            req.AddListenerForAllRecords(grabber);
            HSSFEventFactory factory = new HSSFEventFactory();

            factory.ProcessEvents(req, din);
            din.Close();

            // Should've found one
            Assert.AreEqual(1, grabber.chartTitleFormatRecords.Count);
            // And it should be of something interesting
            ChartTitleFormatRecord r =
                (ChartTitleFormatRecord)grabber.chartTitleFormatRecords[0];

            Assert.AreEqual(3, r.GetFormatCount());
        }
Beispiel #2
0
 /// <summary>
 /// Read the given stream from the file
 /// </summary>
 /// <param name="streamName"></param>
 /// <returns></returns>
 public byte[] ReadStream(String streamName)
 {
     byte[] contents;
     using (Stream stream = PoiFS.CreatePOIFSDocumentReader(streamName))
     {
         contents = new byte[stream.Length];
         stream.Read(contents, 0, contents.Length);
     }
     return(contents);
 }
Beispiel #3
0
        public void SetUp()
        {
            models  = new ArrayList(3);
            factory = new ModelFactory();
            book    = new HSSFWorkbook();
            MemoryStream    stream = (MemoryStream)SetupRunFile(book);
            POIFSFileSystem fs     = new POIFSFileSystem(
                new MemoryStream(stream.ToArray())
                );

            in1 = fs.CreatePOIFSDocumentReader("Workbook");
        }
        public void TestOK()
        {
            Stream          is1 = HSSFTestDataSamples.OpenSampleFileStream("Simple.xls");
            POIFSFileSystem fs  = new POIFSFileSystem(is1);

            //set POIFS properties before constructing HSSFWorkbook
            SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.Create(fs.CreatePOIFSDocumentReader(SummaryInformation.DEFAULT_STREAM_NAME));

            summary1.Title = (title);

            fs.Root.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME).Delete();
            fs.CreateDocument(summary1.ToStream(), SummaryInformation.DEFAULT_STREAM_NAME);

            HSSFWorkbook wb = new HSSFWorkbook(fs);

            MemoryStream out1 = new MemoryStream();

            wb.Write(out1);
            out1.Close();

            //read the property
            POIFSFileSystem    fs2      = new POIFSFileSystem(new MemoryStream(out1.ToArray()));
            SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.Create(fs2.CreatePOIFSDocumentReader(SummaryInformation.DEFAULT_STREAM_NAME));

            Assert.AreEqual(title, summary2.Title);
        }
        public void TestFail()
        {
            Stream          is1 = HSSFTestDataSamples.OpenSampleFileStream("Simple.xls");
            POIFSFileSystem fs  = new POIFSFileSystem(is1);

            HSSFWorkbook wb = new HSSFWorkbook(fs);

            //set POIFS properties after constructing HSSFWorkbook
            //(a piece of code that used to work up to POI 3.0.2)
            SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.Create(fs.CreatePOIFSDocumentReader(SummaryInformation.DEFAULT_STREAM_NAME));

            summary1.Title = (title);
            //Write the modified property back to POIFS
            fs.Root.GetEntry(SummaryInformation.DEFAULT_STREAM_NAME).Delete();
            fs.CreateDocument(summary1.ToStream(), SummaryInformation.DEFAULT_STREAM_NAME);

            //save the workbook and read the property
            MemoryStream out1 = new MemoryStream();

            wb.Write(out1);
            out1.Close();

            POIFSFileSystem    fs2      = new POIFSFileSystem(new MemoryStream(out1.ToArray()));
            SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.Create(fs2.CreatePOIFSDocumentReader(SummaryInformation.DEFAULT_STREAM_NAME));

            //Assert.Failing assertion
            Assert.AreEqual(title, summary2.Title);
        }
Beispiel #6
0
        /// <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.CreatePOIFSDocumentReader("Workbook");

            return(AbortableProcessEvents(req, in1));
        }
Beispiel #7
0
        /// <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.CreatePOIFSDocumentReader("Workbook");

            ProcessEvents(req, in1);
        }