Пример #1
0
        internal ElementAction GetElementAction(OpenXmlElement element, FileFormatVersions format)
        {
            if (format == (FileFormatVersions.Office2010 | FileFormatVersions.Office2007) || format.All())
            {
                return(ElementAction.Normal);
            }

            if (element is AlternateContent)
            {
                return(ElementAction.ACBlock);
            }

            if (element.IsInVersion(format))
            {
                return(ElementAction.Normal);
            }

            if (IsIgnorableNs(element.NamespaceUri))
            {
                if (IsPreservedElement(element.NamespaceUri, element.LocalName))
                {
                    return(ElementAction.Normal);
                }

                if (IsProcessContent(element.NamespaceUri, element.LocalName))
                {
                    return(ElementAction.ProcessContent);
                }

                return(ElementAction.Ignore);
            }

            return(ElementAction.Normal);
        }
        /// <summary>
        /// Throws if the <see cref="OpenXmlElement"/> is not supported in the given version
        /// </summary>
        /// <param name="version">Version to check</param>
        /// <param name="element">Element to validate</param>
        public static void ThrowIfNotInVersion(this FileFormatVersions version, OpenXmlElement element)
        {
            version.ThrowExceptionIfFileFormatNotSupported(nameof(version));

            if (!element.IsInVersion(version))
            {
                throw new InvalidOperationException(SR.Format(ExceptionMessages.ElementIsNotInOfficeVersion, version.GetOfficeYear()));
            }
        }
        /// <summary>
        /// Throws if the <see cref="OpenXmlElement"/> is not supported in the given version
        /// </summary>
        /// <param name="version">Version to check</param>
        /// <param name="element">Element to validate</param>
        public static void ThrowIfNotInVersion(this FileFormatVersions version, OpenXmlElement element)
        {
            version.ThrowExceptionIfFileFormatNotSupported(nameof(version));

            if (!element.IsInVersion(version))
            {
                var message = string.Format(CultureInfo.CurrentCulture, ExceptionMessages.ElementIsNotInOfficeVersion, version.GetOfficeYear());

                throw new InvalidOperationException(message);
            }
        }