Bullets.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 GrapeCity.Documents.Word;
  7.  
  8. namespace DsWordWeb.Demos
  9. {
  10. // This sample demonstrates how to create a simple bullet list.
  11. // See the NumberedList sample for how to create a numbered list.
  12. public class Bullets
  13. {
  14. public GcWordDocument CreateDocx()
  15. {
  16. GcWordDocument doc = new GcWordDocument();
  17. var pars = doc.Body.Paragraphs;
  18. pars.Add("Example of a bullet list with three levels:");
  19.  
  20. // A ListTemplate is used to make paragraphs part of a list:
  21. var myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate");
  22.  
  23. // Action to add a list item:
  24. Action<string, int> addListItem = (t_, l_) => {
  25. var p_ = pars.Add(t_);
  26. // This makes a paragraph a list item:
  27. p_.ListFormat.Template = myListTemplate;
  28. // Set the item's nesting level (first level is 0):
  29. p_.ListFormat.LevelNumber = l_;
  30. // This ensures item spacing consistent with MS Word:
  31. p_.Style = doc.Styles[BuiltInStyleId.ListParagraph];
  32. };
  33.  
  34. // Build a bullet list with 3 levels of nesting:
  35. addListItem("Bullet item 1", 0);
  36. addListItem("Bullet item 2", 0);
  37. addListItem("Bullet item 3", 0);
  38. addListItem("Nested bullet item 1", 1);
  39. addListItem("Nested bullet item 2", 1);
  40. addListItem("Double nested bullet item 1", 2);
  41. addListItem("Double nested bullet item 2", 2);
  42. addListItem("Nested bullet item 3", 1);
  43. addListItem("Bullet item 4", 0);
  44.  
  45. // Done:
  46. return doc;
  47. }
  48. }
  49. }
  50.