/// <summary>
        /// Find a specified AbstractNum by its ID and update its definition to make it multi-level.
        /// </summary>
        private void EnsureMultilevel(int absNumId, bool cascading = false)
        {
            AbstractNum absNumMultilevel = mainPart.NumberingDefinitionsPart.Numbering.Elements <AbstractNum>().SingleOrDefault(a => a.AbstractNumberId.Value == absNumId);

            if (absNumMultilevel != null && absNumMultilevel.MultiLevelType.Val == MultiLevelValues.SingleLevel)
            {
                Level level1 = absNumMultilevel.GetFirstChild <Level>();
                absNumMultilevel.MultiLevelType.Val = MultiLevelValues.Multilevel;

                // skip the first level, starts to 2
                for (int i = 2; i < 10; i++)
                {
                    Level level = new Level {
                        StartNumberingValue = new StartNumberingValue()
                        {
                            Val = 1
                        },
                        NumberingFormat = new NumberingFormat()
                        {
                            Val = level1.NumberingFormat.Val
                        },
                        LevelIndex = i - 1
                    };

                    if (cascading)
                    {
                        // if we're cascading, that means we don't want any identation
                        // + our leveltext should contain the previous levels as well
                        StringBuilder lvlText = new StringBuilder();

                        for (int lvlIndex = 1; lvlIndex <= i; lvlIndex++)
                        {
                            lvlText.AppendFormat("%{0}.", lvlIndex);
                        }

                        level.LevelText = new LevelText()
                        {
                            Val = lvlText.ToString()
                        };
                    }
                    else
                    {
                        level.LevelText = new LevelText()
                        {
                            Val = "%" + i + "."
                        };
                        level.PreviousParagraphProperties =
                            new PreviousParagraphProperties {
                            Indentation = new Indentation()
                            {
                                Left = (720 * i).ToString(CultureInfo.InvariantCulture), Hanging = "360"
                            }
                        };
                    }

                    absNumMultilevel.Append(level);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Find a specified AbstractNum by its ID and update its definition to make it multi-level.
        /// </summary>
        private void EnsureMultilevel(int absNumId)
        {
            AbstractNum absNumMultilevel = null;

            foreach (AbstractNum absNum in mainPart.NumberingDefinitionsPart.Numbering.Elements <AbstractNum>())
            {
                if (absNum.AbstractNumberId == absNumId)
                {
                    absNumMultilevel = absNum;
                    break;
                }
            }


            if (absNumMultilevel != null && absNumMultilevel.MultiLevelType.Val == MultiLevelValues.SingleLevel)
            {
                Level level1 = absNumMultilevel.GetFirstChild <Level>();
                absNumMultilevel.MultiLevelType.Val = MultiLevelValues.Multilevel;

                // skip the first level, starts to 2
                for (int i = 2; i < 10; i++)
                {
                    absNumMultilevel.Append(new Level {
                        StartNumberingValue = new StartNumberingValue()
                        {
                            Val = 1
                        },
                        NumberingFormat = new NumberingFormat()
                        {
                            Val = level1.NumberingFormat.Val
                        },
                        LevelIndex = i - 1,
                        LevelText  = new LevelText()
                        {
                            Val = "%" + i + "."
                        },
                        PreviousParagraphProperties = new PreviousParagraphProperties {
                            Indentation = new Indentation()
                            {
                                Left = (720 * i).ToString(CultureInfo.InvariantCulture), Hanging = "360"
                            }
                        }
                    });
                }
            }
        }