BuiltInListStyles.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Collections.Generic;
  10. using GrapeCity.Documents.Word;
  11. using GrapeCity.Documents.Imaging;
  12.  
  13. namespace DsWordWeb.Demos
  14. {
  15. // This sample demoes all built-in list template available in DsWord.
  16. public class BuiltInListStyles
  17. {
  18. public GcWordDocument CreateDocx()
  19. {
  20. var doc = new GcWordDocument();
  21. var pars = doc.Body.Paragraphs;
  22.  
  23. pars.Add("Demo of All Built-in List Templates", doc.Styles[BuiltInStyleId.Title]);
  24.  
  25. int n = 0;
  26. foreach (BuiltInListTemplateId id in Enum.GetValues(typeof(BuiltInListTemplateId)))
  27. {
  28. var listTemplate = doc.ListTemplates.Add(id, $"listTemplate{n++}");
  29. pars.Add($"List formatted using built-in list template '{listTemplate.Name}':");
  30. int m = 0;
  31. Stack<int> levels = new Stack<int>(new int[] { m });
  32. foreach (var i in new int[]{ 0, 0, 0, 1, 1, 2, 2, 2, 1 })
  33. {
  34. if (i > levels.Count)
  35. {
  36. levels.Push(m);
  37. m = 0;
  38. }
  39. else if (i < levels.Count)
  40. m = levels.Pop();
  41.  
  42. var p = pars.Add($"List item {m++} on level {levels.Count}.", doc.Styles[BuiltInStyleId.ListParagraph]);
  43. p.ListFormat.Template = listTemplate;
  44. p.ListFormat.LevelNumber = i;
  45. }
  46. }
  47.  
  48. // Done:
  49. return doc;
  50. }
  51. }
  52. }
  53.