コード例 #1
0
        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());
        }
コード例 #2
0
        public void TestWithCrazyContinueRecords()
        {
            // Some files have crazy ordering of their continue records
            // Check that we don't break on them (bug #42844)

            HSSFRequest      req        = new HSSFRequest();
            MockHSSFListener mockListen = new MockHSSFListener();

            req.AddListenerForAllRecords(mockListen);

            POIFSFileSystem  fs      = new POIFSFileSystem(OpenSample("ContinueRecordProblem.xls"));
            HSSFEventFactory factory = new HSSFEventFactory();

            factory.ProcessWorkbookEvents(req, fs);

            Record[] recs = mockListen.GetRecords();
            // Check we got the records
            Assert.IsTrue(recs.Length > 100);

            // And none of them are continue ones
            for (int i = 0; i < recs.Length; i++)
            {
                Assert.IsFalse(recs[i] is ContinueRecord);
            }

            // Check that the last few records are as we expect
            // (Makes sure we don't accidently skip the end ones)
            int numRec = recs.Length;

            Assert.AreEqual(typeof(DVALRecord), recs[numRec - 3].GetType());
            Assert.AreEqual(typeof(DVRecord), recs[numRec - 2].GetType());
            Assert.AreEqual(typeof(EOFRecord), recs[numRec - 1].GetType());
        }
コード例 #3
0
        public void TestUnknownContinueRecords()
        {
            HSSFRequest      req        = new HSSFRequest();
            MockHSSFListener mockListen = new MockHSSFListener();

            req.AddListenerForAllRecords(mockListen);

            POIFSFileSystem  fs      = new POIFSFileSystem(OpenSample("42844.xls"));
            HSSFEventFactory factory = new HSSFEventFactory();

            factory.ProcessWorkbookEvents(req, fs);

            Assert.IsTrue(true, "no errors while Processing the file");
        }
コード例 #4
0
        /// <summary>
        /// Initiates the processing of the XLS file to strings
        /// </summary>
        public void Process()
        {
            var listener = new MissingRecordAwareHSSFListener(this);

            _formatListener = new FormatTrackingHSSFListener(listener);

            var factory = new HSSFEventFactory();
            var request = new HSSFRequest();

            _workbookBuildingListener = new EventWorkbookBuilder.SheetRecordCollectingListener(_formatListener);
            request.AddListenerForAllRecords(_workbookBuildingListener);

            factory.ProcessWorkbookEvents(request, _fs);
        }
コード例 #5
0
        /// <summary>
        /// Triggers the extraction.
        /// </summary>
        /// <returns></returns>
        private TextListener TriggerExtraction()
        {
            TextListener tl = new TextListener(includeSheetNames, formulasNotResults);
            FormatTrackingHSSFListener ft = new FormatTrackingHSSFListener(tl);

            tl.ft = ft;

            // Register and process
            HSSFEventFactory factory = new HSSFEventFactory();
            HSSFRequest      request = new HSSFRequest();

            request.AddListenerForAllRecords(ft);

            factory.ProcessWorkbookEvents(request, fs);

            return(tl);
        }
コード例 #6
0
        public void TestAbortStops()
        {
            AbortableCountingListener l = new AbortableCountingListener(1);

            HSSFRequest req = new HSSFRequest();

            req.AddListenerForAllRecords(l);

            HSSFEventFactory f = new HSSFEventFactory();

            Assert.AreEqual(0, l.countSeen);
            Assert.AreEqual(null, l.lastRecordSeen);

            POIFSFileSystem fs  = openSample();
            short           res = f.AbortableProcessWorkbookEvents(req, fs);

            Assert.AreEqual(1234, res);
            Assert.AreEqual(1, l.countSeen);
            Assert.AreEqual(BOFRecord.sid, l.lastRecordSeen.Sid);
        }
コード例 #7
0
        private void ProcessFile(string filename)
        {
            HSSFRequest req = new HSSFRequest();

            mockListen = new MockHSSFListener();
            listener   = new FormatTrackingHSSFListener(mockListen);
            req.AddListenerForAllRecords(listener);

            HSSFEventFactory factory = new HSSFEventFactory();

            try
            {
                Stream          is1 = HSSFTestDataSamples.OpenSampleFileStream(filename);
                POIFSFileSystem fs  = new POIFSFileSystem(is1);
                factory.ProcessWorkbookEvents(req, fs);
            }
            catch (IOException)
            {
                throw;
            }
        }
コード例 #8
0
        public void TestAbortingBasics()
        {
            AbortableCountingListener l = new AbortableCountingListener(1000);

            HSSFRequest req = new HSSFRequest();

            req.AddListenerForAllRecords(l);

            HSSFEventFactory f = new HSSFEventFactory();

            Assert.AreEqual(0, l.countSeen);
            Assert.AreEqual(null, l.lastRecordSeen);

            POIFSFileSystem fs  = openSample();
            short           res = f.AbortableProcessWorkbookEvents(req, fs);

            Assert.AreEqual(0, res);
            //Assert.AreEqual(175, l.countSeen);
            Assert.AreEqual(176, l.countSeen); //Tony Qu add a sheetext record, so this value should be 176
            Assert.AreEqual(EOFRecord.sid, l.lastRecordSeen.Sid);
        }
コード例 #9
0
        public void SetUp()
        {
            HSSFRequest req = new HSSFRequest();

            mockListen = new MockHSSFListener();
            listener   = new EventWorkbookBuilder.SheetRecordCollectingListener(mockListen);
            req.AddListenerForAllRecords(listener);

            HSSFEventFactory factory = new HSSFEventFactory();

            try
            {
                Stream          is1 = HSSFTestDataSamples.OpenSampleFileStream("3dFormulas.xls");
                POIFSFileSystem fs  = new POIFSFileSystem(is1);
                factory.ProcessWorkbookEvents(req, fs);
            }
            catch (IOException)
            {
                throw;
            }
        }
コード例 #10
0
        private void ReadRecords(String sampleFileName)
        {
            HSSFRequest      req                    = new HSSFRequest();
            MockHSSFListener mockListen             = new MockHSSFListener();
            MissingRecordAwareHSSFListener listener = new MissingRecordAwareHSSFListener(mockListen);

            req.AddListenerForAllRecords(listener);

            HSSFEventFactory factory = new HSSFEventFactory();

            try
            {
                Stream          is1 = HSSFTestDataSamples.OpenSampleFileStream(sampleFileName);
                POIFSFileSystem fs  = new POIFSFileSystem(is1);
                factory.ProcessWorkbookEvents(req, fs);
            }
            catch (IOException)
            {
                throw;
            }

            r = mockListen.GetRecords();
            Assert.IsTrue(r.Length > 100);
        }
コード例 #11
0
        public void TestWithMissingRecords()
        {
            HSSFRequest      req        = new HSSFRequest();
            MockHSSFListener mockListen = new MockHSSFListener();

            req.AddListenerForAllRecords(mockListen);

            POIFSFileSystem  fs      = new POIFSFileSystem(OpenSample("SimpleWithSkip.xls"));
            HSSFEventFactory factory = new HSSFEventFactory();

            factory.ProcessWorkbookEvents(req, fs);

            Record[] recs = mockListen.GetRecords();
            // Check we got the records
            Assert.IsTrue(recs.Length > 100);

            // Check that the last few records are as we expect
            // (Makes sure we don't accidently skip the end ones)
            int numRec = recs.Length;

            Assert.AreEqual(typeof(WindowTwoRecord), recs[numRec - 3].GetType());
            Assert.AreEqual(typeof(SelectionRecord), recs[numRec - 2].GetType());
            Assert.AreEqual(typeof(EOFRecord), recs[numRec - 1].GetType());
        }