public void TestMissingHeaderFooterRecord_bug47244()
        {
            // noHeaderFooter47244.xls was Created by a slightly modified POI
            // which omitted the HEADER/FOOTER records
            IWorkbook  wb    = HSSFTestDataSamples.OpenSampleWorkbook("noHeaderFooter47244.xls");
            ISheet     sheet = wb.GetSheetAt(0);
            HSSFFooter footer;

            try
            {
                footer = (HSSFFooter)sheet.Footer;
            }
            catch (NullReferenceException)
            {
                throw new AssertionException("Identified bug 47244a");
            }
            Assert.AreEqual("", footer.RawText);
            HSSFHeader header = (HSSFHeader)sheet.Header;

            Assert.AreEqual("", header.RawText);

            // make sure header / footer is properly linked to underlying data
            HSSFHeader header2 = (HSSFHeader)sheet.Header;

            header.Center = (/*setter*/ "foo");
            Assert.AreEqual("foo", header2.Center);

            HSSFFooter footer2 = (HSSFFooter)sheet.Footer;

            footer.Center = (/*setter*/ "bar");
            Assert.AreEqual("bar", footer2.Center);
        }
Example #2
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.AreEqual(simple, HSSFHeader.StripFields(simple));
            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.Sheet s = wb.GetSheetAt(0);
            Header 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));
        }
Example #3
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));
        }
Example #4
0
        private void SetWorkbook <T>(IList <T> records, String fileName, Root root, HSSFWorkbook workbook, ISheet sheet)
        {
            #region 设置页眉页脚
            if (root.isMargin)
            {
                sheet.Header.Left  = "\n\n项目名称:" + fileName + "\n";
                sheet.Header.Right = "\n\n第" + HSSFHeader.Page + "页 共" + HSSFHeader.NumPages + "页\n";
                sheet.Footer.Right = root.company;
            }
            if (root.isHeadMargin)
            {
                sheet.Header.Center = HSSFHeader.StartBold + HSSFHeader.FontSize(20) + root.head.sheetname + HSSFHeader.EndBold;
            }
            #endregion

            List <PropertyInfo> columns = new List <PropertyInfo>();
            // 设置头部
            SetHeader <T>(root, workbook, sheet, columns);

            // 填充数据
            SetData <T>(records, root, workbook, sheet, columns);
        }