Exemplo n.º 1
0
        public static AbstractNum CreateAbstractNum(int abstractNumId)
        {
            if (abstractNumId < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var an = new AbstractNum {
                AbstractNumberId = abstractNumId
            };

            an.AppendChild(LevelFactory.CreateLevel(NumberFormatValues.Decimal, 720, 360));
            an.AppendChild(LevelFactory.CreateLevel(NumberFormatValues.Decimal, 720 * 2, 360));
            an.AppendChild(LevelFactory.CreateLevel(NumberFormatValues.Decimal, 720 * 3, 360));

            return(an);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the level to abstract numbering definition.
        /// </summary>
        /// <param name="renderer">The renderer.</param>
        /// <param name="level">The level to add (1..9).</param>
        /// <param name="isOrdered">If set to <c>true</c>, the list items will start with a number. If set to false, the items will start with a bullet.</param>
        private void AddLevelToAbstractNumberingDefinition(OpenXMLRenderer renderer, int level, bool isOrdered)
        {
            var presentLevels = _currentAbstractNumberingDefinition.ChildElements.OfType <Level>().Count();

            if (level <= presentLevels)
            {
                return;
            }

            var levelDef = GenerateLevel(level, isOrdered);

            if (null != levelDef)
            {
                _currentAbstractNumberingDefinition.AppendChild(levelDef);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the abstract numbering definition. The abstract numbering definition can be thought of as the list class, which can have multiple instances.
        /// In this definition the styles of the different list levels will be defined, but here we add the definitions part only.
        /// The level definitions will be added to this on demand later.
        /// </summary>
        /// <param name="renderer">The renderer.</param>
        /// <returns>The abstract numbering definition.</returns>
        private AbstractNum AddAbstractNumberingDefinition(OpenXMLRenderer renderer)
        {
            var _wordDocument = renderer._wordDocument;
            // Introduce bulleted numbering in case it will be needed at some point
            NumberingDefinitionsPart numberingPart = _wordDocument.MainDocumentPart.NumberingDefinitionsPart;

            if (numberingPart == null)
            {
                numberingPart = _wordDocument.MainDocumentPart.AddNewPart <NumberingDefinitionsPart>("NumberingDefinitionsPart001");
                var element = new Numbering();
                element.Save(numberingPart);
            }

            // Insert an AbstractNum into the numbering part numbering list.
            // The order seems to matter or it will not pass the
            // Open XML SDK Productity Tools validation test.
            // AbstractNum comes first and then NumberingInstance and we want to
            // insert this AFTER the last AbstractNum and BEFORE the first NumberingInstance or we will get a validation error.
            var abstractNumberId = numberingPart.Numbering.Elements <AbstractNum>().Count() + 1;
            var abstractNum1     = new AbstractNum()
            {
                AbstractNumberId = abstractNumberId
            };

            abstractNum1.AppendChild(new MultiLevelType()
            {
                Val = MultiLevelValues.HybridMultilevel
            });

            if (abstractNumberId == 1)
            {
                numberingPart.Numbering.Append(abstractNum1);
            }
            else
            {
                AbstractNum lastAbstractNum = numberingPart.Numbering.Elements <AbstractNum>().Last();
                numberingPart.Numbering.InsertAfter(abstractNum1, lastAbstractNum);
            }
            return(abstractNum1);
        }