Esempio n. 1
0
        //private void OpenHeaderFooter(OXmlOpenHeaderFooter element)
        //{
        //    CreateSectionProperties();
        //    OpenXmlCompositeElement headerFooter;
        //    if (element.Header)
        //    {
        //        HeaderPart headerPart = _mainPart.AddNewPart<HeaderPart>();
        //        headerFooter = new Header();
        //        headerPart.Header = (Header)headerFooter;
        //        string headerPartId = _mainPart.GetIdOfPart(headerPart);
        //        _sectionProperties.AppendChild(new HeaderReference { Id = headerPartId, Type = element.HeaderType });
        //    }
        //    else
        //    {
        //        FooterPart footerPart = _mainPart.AddNewPart<FooterPart>();
        //        headerFooter = new Footer();
        //        footerPart.Footer = (Footer)headerFooter;
        //        string footerPartId = _mainPart.GetIdOfPart(footerPart);
        //        _sectionProperties.AppendChild(new FooterReference { Id = footerPartId, Type = element.HeaderType });
        //    }
        //    AddHeaderFooterNamespaceDeclaration((OpenXmlPartRootElement)headerFooter);

        //    SetHeaderFooterProperties(element.HeaderType);

        //    _element = headerFooter;
        //    _headerFooter = true;
        //}

        private void OpenHeader(OXmlOpenHeaderElement element)
        {
            CreateSectionProperties();
            //if (element.Header)
            //{
            HeaderPart headerPart          = _mainPart.AddNewPart <HeaderPart>();
            OpenXmlCompositeElement header = new Header();

            headerPart.Header = (Header)header;
            string headerPartId = _mainPart.GetIdOfPart(headerPart);

            _sectionProperties.AppendChild(new HeaderReference {
                Id = headerPartId, Type = element.HeaderType
            });
            //}
            //else
            //{
            //    FooterPart footerPart = _mainPart.AddNewPart<FooterPart>();
            //    headerFooter = new Footer();
            //    footerPart.Footer = (Footer)headerFooter;
            //    string footerPartId = _mainPart.GetIdOfPart(footerPart);
            //    _sectionProperties.AppendChild(new FooterReference { Id = footerPartId, Type = element.HeaderType });
            //}
            AddHeaderFooterNamespaceDeclaration((OpenXmlPartRootElement)header);

            SetHeaderFooterProperties(element.HeaderType);

            _element = header;
            //_headerFooter = true;
            _currentElement = OXmlDocElementType.Header;
        }
 public OXmlOpenHeaderElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
 {
     OXmlOpenHeaderElement element = new OXmlOpenHeaderElement();
     while (true)
     {
         BsonType bsonType = bsonReader.ReadBsonType();
         if (bsonType == BsonType.EndOfDocument)
             break;
         string name = bsonReader.ReadName();
         switch (name.ToLower())
         {
             case "type":
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong type value {bsonType}");
                 string type = bsonReader.ReadString();
                 //"openfooter"
                 if (type.ToLower() != "openheader")
                     throw new PBException($"invalid Type {type} when deserialize OXmlOpenHeader");
                 break;
             case "headertype":
                 if (bsonType == BsonType.Null)
                     break;
                 if (bsonType != BsonType.String)
                     throw new PBException($"wrong HeaderType value {bsonType}");
                 element.HeaderType = bsonReader.ReadString().zParseEnum<HeaderFooterValues>();
                 break;
             default:
                 //OpenHeaderFooter
                 throw new PBException($"unknow OpenHeader value \"{name}\"");
         }
     }
     return element;
 }
Esempio n. 3
0
        //private OXmlElement CreateOpenHeaderFooter(BsonDocument element, bool header)
        //{
        //    if (_headerFooter)
        //        throw new PBException("header-footer cant contain nested header-footer");
        //    OXmlOpenHeaderFooter openHeaderFooter = new OXmlOpenHeaderFooter();
        //    openHeaderFooter.Header = header;
        //    openHeaderFooter.HeaderType = element.zGet("HeaderType").zAsString().zTryParseEnum(HeaderFooterValues.Default);
        //    _headerFooter = true;
        //    return openHeaderFooter;
        //}

        private OXmlElement CreateOpenHeader(BsonDocument element)
        {
            if (_headerFooter)
            {
                throw new PBException("header-footer cant contain nested header-footer");
            }
            OXmlOpenHeaderElement openHeader = new OXmlOpenHeaderElement();

            openHeader.HeaderType = element.zGet("HeaderType").zAsString().zTryParseEnum(HeaderFooterValues.Default);
            _headerFooter         = true;
            return(openHeader);
        }
Esempio n. 4
0
        //private void OpenHeaderFooter(OXmlOpenHeaderFooter element)
        //{
        //    CreateSectionProperties();
        //    OpenXmlCompositeElement headerFooter;
        //    if (element.Header)
        //    {
        //        HeaderPart headerPart = _mainPart.AddNewPart<HeaderPart>();
        //        headerFooter = new Header();
        //        headerPart.Header = (Header)headerFooter;
        //        string headerPartId = _mainPart.GetIdOfPart(headerPart);
        //        _sectionProperties.AppendChild(new HeaderReference { Id = headerPartId, Type = element.HeaderType });
        //    }
        //    else
        //    {
        //        FooterPart footerPart = _mainPart.AddNewPart<FooterPart>();
        //        headerFooter = new Footer();
        //        footerPart.Footer = (Footer)headerFooter;
        //        string footerPartId = _mainPart.GetIdOfPart(footerPart);
        //        _sectionProperties.AppendChild(new FooterReference { Id = footerPartId, Type = element.HeaderType });
        //    }
        //    AddHeaderFooterNamespaceDeclaration((OpenXmlPartRootElement)headerFooter);

        //    SetHeaderFooterProperties(element.HeaderType);

        //    _element = headerFooter;
        //    _headerFooter = true;
        //}

        private void OpenHeader(OXmlOpenHeaderElement element)
        {
            CreateSectionProperties();
            //if (element.Header)
            //{
                HeaderPart headerPart = _mainPart.AddNewPart<HeaderPart>();
            OpenXmlCompositeElement header = new Header();
                headerPart.Header = (Header)header;
                string headerPartId = _mainPart.GetIdOfPart(headerPart);
                _sectionProperties.AppendChild(new HeaderReference { Id = headerPartId, Type = element.HeaderType });
            //}
            //else
            //{
            //    FooterPart footerPart = _mainPart.AddNewPart<FooterPart>();
            //    headerFooter = new Footer();
            //    footerPart.Footer = (Footer)headerFooter;
            //    string footerPartId = _mainPart.GetIdOfPart(footerPart);
            //    _sectionProperties.AppendChild(new FooterReference { Id = footerPartId, Type = element.HeaderType });
            //}
            AddHeaderFooterNamespaceDeclaration((OpenXmlPartRootElement)header);

            SetHeaderFooterProperties(element.HeaderType);

            _element = header;
            //_headerFooter = true;
            _currentElement = OXmlDocElementType.Header;
        }
Esempio n. 5
0
        //private OXmlElement CreateOpenHeaderFooter(BsonDocument element, bool header)
        //{
        //    if (_headerFooter)
        //        throw new PBException("header-footer cant contain nested header-footer");
        //    OXmlOpenHeaderFooter openHeaderFooter = new OXmlOpenHeaderFooter();
        //    openHeaderFooter.Header = header;
        //    openHeaderFooter.HeaderType = element.zGet("HeaderType").zAsString().zTryParseEnum(HeaderFooterValues.Default);
        //    _headerFooter = true;
        //    return openHeaderFooter;
        //}

        private OXmlElement CreateOpenHeader(BsonDocument element)
        {
            if (_headerFooter)
                throw new PBException("header-footer cant contain nested header-footer");
            OXmlOpenHeaderElement openHeader = new OXmlOpenHeaderElement();
            openHeader.HeaderType = element.zGet("HeaderType").zAsString().zTryParseEnum(HeaderFooterValues.Default);
            _headerFooter = true;
            return openHeader;
        }