ListBuiltInStyles.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 GrapeCity.Documents.Word;
  10. using GrapeCity.Documents.Imaging;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This sample lists all built-in styles available in DsWord.
  15. public class ListBuiltInStyles
  16. {
  17. public GcWordDocument CreateDocx()
  18. {
  19. var doc = new GcWordDocument();
  20. var sec = doc.Body.Sections.First;
  21. var pars = sec.GetRange().Paragraphs;
  22.  
  23. pars.Add("List of All Built-in Styles", doc.Styles[BuiltInStyleId.Title]);
  24.  
  25. // List all built-in style names and types.
  26. // Note that BuiltInStyleId.User is a special case that is not associated
  27. // with any built-in style. This value is returned by the Style.BuiltInId
  28. // property for user-defined styles, but cannot be used as an index
  29. // on the Styles collection (an exception will occur):
  30. foreach (BuiltInStyleId id in Enum.GetValues(typeof(BuiltInStyleId)))
  31. if (id != BuiltInStyleId.User)
  32. pars.Add($"Style name: '{doc.Styles[id].Name}', type: '{doc.Styles[id].Type}'.");
  33.  
  34. // Done:
  35. return doc;
  36. }
  37. }
  38. }
  39.