Example #1
0
        public OfficePart CreateCustomPart(XmlPart partType)
        {
            string relativePath;
            string relType;

            switch (partType)
            {
            case XmlPart.RibbonX12:
                relativePath = "/customUI/customUI.xml";
                relType      = CustomUiPartRelType;
                break;

            case XmlPart.RibbonX14:
                relativePath = "/customUI/customUI14.xml";
                relType      = CustomUi14PartRelType;
                break;

            case XmlPart.Qat12:
                relativePath = "/customUI/qat.xml";
                relType      = QatPartRelType;
                break;

            default:
                throw new ArgumentException($"Unexpected {nameof(partType)}: {partType}");
            }

            var customUiUri  = new Uri(relativePath, UriKind.Relative);
            var relationship = this.UnderlyingPackage.CreateRelationship(customUiUri, TargetMode.Internal, relType);

            OfficePart part;

            if (!this.UnderlyingPackage.PartExists(customUiUri))
            {
                part = new OfficePart(this.UnderlyingPackage.CreatePart(customUiUri, "application/xml"), partType, relationship.Id);
            }
            else
            {
                part = new OfficePart(this.UnderlyingPackage.GetPart(customUiUri), partType, relationship.Id);
            }

            if (this.Parts == null)
            {
                this.Parts = new List <OfficePart>();
            }

            this.Parts.Add(part);
            this.IsDirty = true;

            return(part);
        }
        public OfficePart CreateCustomPart(XmlParts partType)
        {
            string relativePath;
            string relType;

            switch (partType)
            {
            case XmlParts.RibbonX12:
                relativePath = "/customUI/customUI.xml";
                relType      = CustomUiPartRelType;
                break;

            case XmlParts.RibbonX14:
                relativePath = "/customUI/customUI14.xml";
                relType      = CustomUi14PartRelType;
                break;

            case XmlParts.Qat12:
                relativePath = "/customUI/qat.xml";
                relType      = QatPartRelType;
                break;

            default:
                Debug.Assert(false, "Unknown type");
                // ReSharper disable once HeuristicUnreachableCode
                return(null);
            }

            var customUiUri  = new Uri(relativePath, UriKind.Relative);
            var relationship = this.UnderlyingPackage.CreateRelationship(customUiUri, TargetMode.Internal, relType);

            OfficePart part;

            if (!this.UnderlyingPackage.PartExists(customUiUri))
            {
                part = new OfficePart(this.UnderlyingPackage.CreatePart(customUiUri, "application/xml"), partType, relationship.Id);
            }
            else
            {
                part = new OfficePart(this.UnderlyingPackage.GetPart(customUiUri), partType, relationship.Id);
            }

            Debug.Assert(part != null, "Fail to create custom part.");

            this.Parts.Add(part);
            this.IsDirty = true;

            return(part);
        }