SomeCommonStyles.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 GrapeCity.Documents.Word;
  9. using GrapeCity.Documents.Imaging;
  10.  
  11. namespace DsWordWeb.Demos
  12. {
  13. // This sample demonstrates how to use built-in styles
  14. // to format a document.
  15. public class SomeCommonStyles
  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. // Title:
  24. pars.Add("Some Common Built-in Styles (Title)", doc.Styles[BuiltInStyleId.Title]);
  25.  
  26. // Title:
  27. pars.Add("Demonstration of some of the built-in styles. (Subtitle)", doc.Styles[BuiltInStyleId.Subtitle]);
  28.  
  29. // Headings 1-4:
  30. var heading1 = pars.Add("Heading 1", doc.Styles[BuiltInStyleId.Heading1]);
  31. var heading2 = pars.Add("Heading 2", doc.Styles[BuiltInStyleId.Heading2]);
  32. var heading3 = pars.Add("Heading 3", doc.Styles[BuiltInStyleId.Heading3]);
  33. var heading4 = pars.Add("Heading 4", doc.Styles[BuiltInStyleId.Heading4]);
  34.  
  35. // Normal Text:
  36. pars.Add("This and the following 'lorem impum' paragraph use the 'Normal' style.");
  37. pars.Add(SmallPara());
  38.  
  39. // Quote:
  40. pars.Add("The next paragraph uses the 'Quote' style:");
  41. var p = pars.Add(SmallPara(), doc.Styles[BuiltInStyleId.Quote]);
  42. p.Style.ParagraphFormat.KeepTogether = true;
  43.  
  44. // Intense Quote:
  45. pars.Add("The next paragraph uses the 'Intense Quote' style:");
  46. p = pars.Add(SmallPara(), doc.Styles[BuiltInStyleId.IntenseQuote]);
  47. p.Style.ParagraphFormat.KeepTogether = true;
  48.  
  49. // Intense Quote:
  50. pars.Add("The next paragraph uses the 'List Paragraph' style:");
  51. p = pars.Add(SmallPara(), doc.Styles[BuiltInStyleId.ListParagraph]);
  52. p.Style.ParagraphFormat.KeepTogether = true;
  53.  
  54. // Character styles:
  55. p = pars.Add("In this paragraph we demonstrate some of the built-in character styles. ");
  56. var runs = p.GetRange().Runs;
  57. runs.Add("This run uses the 'Strong' style. ", doc.Styles[BuiltInStyleId.Strong]);
  58. runs.Add("A run of normal text. ");
  59. runs.Add("This run uses 'Emphasis' style. ", doc.Styles[BuiltInStyleId.Emphasis]);
  60. runs.Add("A run of normal text. ");
  61. runs.Add("This run uses 'Intense Emphasis' style. ", doc.Styles[BuiltInStyleId.IntenseEmphasis]);
  62. runs.Add("A run of normal text. ");
  63. runs.Add("This run uses 'Subtle Emphasis' style. ", doc.Styles[BuiltInStyleId.SubtleEmphasis]);
  64.  
  65. pars.Add("The End.");
  66.  
  67. // Done:
  68. return doc;
  69.  
  70. string SmallPara()
  71. {
  72. return Util.LoremIpsumPar(2, 3, 4, 5);
  73. }
  74. }
  75. }
  76. }
  77.