コード例 #1
0
        public void HelpfulExceptionOnOldFiles()
        {
            Stream excel4 = POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("testEXCEL_4.xls");

            try
            {
                new HSSFWorkbook(excel4);
                Assert.Fail("Shouldn't be able to load an Excel 4 file");
            }
            catch (OldExcelFormatException e)
            {
                POITestCase.AssertContains(e.Message, "BIFF4");
            }
            excel4.Close();

            Stream excel5 = POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("testEXCEL_5.xls");

            try
            {
                new HSSFWorkbook(excel5);
                Assert.Fail("Shouldn't be able to load an Excel 5 file");
            }
            catch (OldExcelFormatException e)
            {
                POITestCase.AssertContains(e.Message, "BIFF8");
            }
            excel5.Close();

            Stream excel95 = POIDataSamples.GetSpreadSheetInstance().OpenResourceAsStream("testEXCEL_95.xls");

            try
            {
                new HSSFWorkbook(excel95);
                Assert.Fail("Shouldn't be able to load an Excel 95 file");
            }
            catch (OldExcelFormatException e)
            {
                POITestCase.AssertContains(e.Message, "BIFF5");
            }
            excel95.Close();
        }
コード例 #2
0
        protected void AssertMacroContents(POIDataSamples samples, VBAMacroReader r)
        {
            Assert.IsNotNull(r);
            Dictionary <String, String> contents = r.ReadMacros();

            Assert.IsNotNull(contents);
            Assert.IsFalse(contents.Count == 0, "Found 0 macros");

            /*
             * Assert.AreEqual(5, contents.Size());
             *
             * // Check the ones without scripts
             * String[] noScripts = new String[] { "ThisWorkbook",
             *      "Sheet1", "Sheet2", "Sheet3" };
             * foreach (String entry in noScripts) {
             *  Assert.IsTrue(entry, contents.ContainsKey(entry));
             *
             *  String content = contents.Get(entry);
             *  assertContains(content, "Attribute VB_Exposed = True");
             *  assertContains(content, "Attribute VB_Customizable = True");
             *  assertContains(content, "Attribute VB_TemplateDerived = False");
             *  assertContains(content, "Attribute VB_GlobalNameSpace = False");
             *  assertContains(content, "Attribute VB_Exposed = True");
             * }
             */

            // Check the script one
            POITestCase.AssertContains(contents, "Module1");
            String content = contents["Module1"];

            Assert.IsNotNull(content);
            POITestCase.AssertContains(content, "Attribute VB_Name = \"Module1\"");
            //assertContains(content, "Attribute TestMacro.VB_Description = \"This is a test macro\"");

            // And the macro itself
            String testMacroNoSub = expectedMacroContents[samples];

            POITestCase.AssertContains(content, testMacroNoSub);
        }