Exemplo n.º 1
0
        /// <summary>
        /// Saves the header and footer information to the worksheet XML
        /// </summary>
        protected internal void Save()
        {
            //  The header/footer elements must appear in this order, if they appear:
            //  <oddHeader />
            //  <oddFooter />
            //  <evenHeader />
            //  <evenFooter />
            //  <firstHeader />
            //  <firstFooter />

            XmlNode node;

            if (_header != null)
            {
                node =
                    _headerFooterNode.AppendChild(_headerFooterNode.OwnerDocument.CreateElement("oddHeader",
                                                                                                ExcelPackage.schemaMain));
                node.InnerText = Header.GetHeaderFooterText();
            }
            if (_footer != null)
            {
                node =
                    _headerFooterNode.AppendChild(_headerFooterNode.OwnerDocument.CreateElement("oddFooter",
                                                                                                ExcelPackage.schemaMain));
                node.InnerText = Footer.GetHeaderFooterText();
            }

            // only set evenHeader and evenFooter
            if (differentOddEven)
            {
                if (_evenHeader != null)
                {
                    node =
                        _headerFooterNode.AppendChild(_headerFooterNode.OwnerDocument.CreateElement("evenHeader",
                                                                                                    ExcelPackage.
                                                                                                    schemaMain));
                    node.InnerText = EvenHeader.GetHeaderFooterText();
                }
                if (_evenFooter != null)
                {
                    node =
                        _headerFooterNode.AppendChild(_headerFooterNode.OwnerDocument.CreateElement("evenFooter",
                                                                                                    ExcelPackage.
                                                                                                    schemaMain));
                    node.InnerText = EvenFooter.GetHeaderFooterText();
                }
            }

            // only set firstHeader and firstFooter
            if (differentFirst)
            {
                if (_firstHeader != null)
                {
                    node =
                        _headerFooterNode.AppendChild(_headerFooterNode.OwnerDocument.CreateElement("firstHeader",
                                                                                                    ExcelPackage.
                                                                                                    schemaMain));
                    node.InnerText = FirstHeader.GetHeaderFooterText();
                }
                if (_firstFooter != null)
                {
                    node =
                        _headerFooterNode.AppendChild(_headerFooterNode.OwnerDocument.CreateElement("firstFooter",
                                                                                                    ExcelPackage.
                                                                                                    schemaMain));
                    node.InnerText = FirstFooter.GetHeaderFooterText();
                }
            }
        }