SomeCommonStyles.vb
  1. ''
  2. '' This code is part of Document Solutions for Word demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.Drawing
  6. Imports System.IO
  7. Imports System.Linq
  8. Imports GrapeCity.Documents.Word
  9. Imports GrapeCity.Documents.Imaging
  10.  
  11. '' This sample demonstrates how to use built-in styles
  12. '' to format a document.
  13. Public Class SomeCommonStyles
  14. Public Function CreateDocx() As GcWordDocument
  15. Dim doc = New GcWordDocument()
  16. Dim sec = doc.Body.Sections.First
  17. Dim pars = sec.GetRange().Paragraphs
  18.  
  19. '' Title:
  20. pars.Add("Some Common Built-in Styles (Title)", doc.Styles(BuiltInStyleId.Title))
  21.  
  22. '' Title:
  23. pars.Add("Demonstration of some of the built-in styles. (Subtitle)", doc.Styles(BuiltInStyleId.Subtitle))
  24.  
  25. '' Headings 1-4:
  26. Dim heading1 = pars.Add("Heading 1", doc.Styles(BuiltInStyleId.Heading1))
  27. Dim heading2 = pars.Add("Heading 2", doc.Styles(BuiltInStyleId.Heading2))
  28. Dim heading3 = pars.Add("Heading 3", doc.Styles(BuiltInStyleId.Heading3))
  29. Dim heading4 = pars.Add("Heading 4", doc.Styles(BuiltInStyleId.Heading4))
  30.  
  31. '' Normal Text:
  32. pars.Add("This and the following 'lorem impum' paragraph use the 'Normal' style.")
  33. pars.Add(SmallPara())
  34.  
  35. '' Quote:
  36. pars.Add("The next paragraph uses the 'Quote' style:")
  37. Dim p = pars.Add(SmallPara(), doc.Styles(BuiltInStyleId.Quote))
  38. p.Style.ParagraphFormat.KeepTogether = True
  39.  
  40. '' Intense Quote:
  41. pars.Add("The next paragraph uses the 'Intense Quote' style:")
  42. p = pars.Add(SmallPara(), doc.Styles(BuiltInStyleId.IntenseQuote))
  43. p.Style.ParagraphFormat.KeepTogether = True
  44.  
  45. '' Intense Quote:
  46. pars.Add("The next paragraph uses the 'List Paragraph' style:")
  47. p = pars.Add(SmallPara(), doc.Styles(BuiltInStyleId.ListParagraph))
  48. p.Style.ParagraphFormat.KeepTogether = True
  49.  
  50. '' Character styles:
  51. p = pars.Add("In this paragraph we demonstrate some of the built-in character styles. ")
  52. Dim runs = p.GetRange().Runs
  53. runs.Add("This run uses the 'Strong' style. ", doc.Styles(BuiltInStyleId.Strong))
  54. runs.Add("A run of normal text. ")
  55. runs.Add("This run uses 'Emphasis' style. ", doc.Styles(BuiltInStyleId.Emphasis))
  56. runs.Add("A run of normal text. ")
  57. runs.Add("This run uses 'Intense Emphasis' style. ", doc.Styles(BuiltInStyleId.IntenseEmphasis))
  58. runs.Add("A run of normal text. ")
  59. runs.Add("This run uses 'Subtle Emphasis' style. ", doc.Styles(BuiltInStyleId.SubtleEmphasis))
  60.  
  61. pars.Add("The End.")
  62.  
  63. '' Done:
  64. Return doc
  65. End Function
  66.  
  67. Private Function SmallPara() As String
  68. Return Util.LoremIpsumPar(2, 3, 4, 5)
  69. End Function
  70. End Class
  71.