Пример #1
0
        public void TestStripFields()
        {
            String simple         = "I am a Test header";
            String withPage       = "I am a&P Test header";
            String withLots       = "I&A am&N a&P Test&T header&U";
            String withFont       = "I&22 am a&\"Arial,bold\" Test header";
            String withOtherAnds  = "I am a&P Test header&&";
            String withOtherAnds2 = "I am a&P Test header&a&b";

            Assert.IsTrue(0 < HeaderFooter.Fields.AllFields.Count,
                          string.Format(CultureInfo.InvariantCulture, "Fields.AllFields must be initialized before the following tests are working. Fields.AllFields.Count: {0}. ",
                                        HeaderFooter.Fields.AllFields.Count));

            Assert.AreEqual(simple, HSSFHeader.StripFields(simple));
            Assert.AreEqual(simple, HeaderFooter.StripFields(withPage));
            Assert.AreEqual(simple, HSSFHeader.StripFields(withPage));
            Assert.AreEqual(simple, HSSFHeader.StripFields(withLots));
            Assert.AreEqual(simple, HSSFHeader.StripFields(withFont));
            Assert.AreEqual(simple + "&&", HSSFHeader.StripFields(withOtherAnds));
            Assert.AreEqual(simple + "&a&b", HSSFHeader.StripFields(withOtherAnds2));

            // Now Test the default Strip flag
            HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("EmbeddedChartHeaderTest.xls");

            NPOI.SS.UserModel.ISheet s = wb.GetSheetAt(0);
            IHeader head = s.Header;

            Assert.AreEqual("Top Left", head.Left);
            Assert.AreEqual("Top Center", head.Center);
            Assert.AreEqual("Top Right", head.Right);

            head.Left = ("Top &P&F&D Left");
            Assert.AreEqual("Top &P&F&D Left", head.Left);

            Assert.AreEqual("Top  Left", NPOI.HSSF.UserModel.HeaderFooter.StripFields(head.Left));
            // Now even more complex
            head.Center = ("HEADER TEXT &P&N&D&T&Z&F&F&A&G&X END");
            Assert.AreEqual("HEADER TEXT  END", NPOI.HSSF.UserModel.HeaderFooter.StripFields(head.Center));
        }
Пример #2
0
        /**
         * Removes any fields (eg macros, page markers etc) from the string.
         * Normally used to make some text suitable for showing to humans, and the
         * resultant text should not normally be saved back into the document!
         */

        public static String StripFields(string text)
        {
            return(HeaderFooter.StripFields(text));
        }