ProcurementLetter.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.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Word
  8.  
  9. '' This sample builds a nice-looking procurement business letter using tables to create the layout.
  10. Public Class ProcurementLetter
  11. Function CreateDocx() As GcWordDocument
  12. Dim doc = New GcWordDocument()
  13. doc.Styles.DefaultFont.Size = 12
  14. doc.Styles.DefaultParagraphFormat.Spacing.SpaceAfter = 0
  15. doc.Styles(BuiltInStyleId.Normal).Font.Name = "Times New Roman"
  16. doc.Styles(BuiltInStyleId.Normal).Font.Size = 10
  17.  
  18. Dim sec = doc.Body.Sections.First
  19. sec.PageSetup.Size.PaperSize = PaperSize.PaperA4
  20. Dim footer = sec.Footers(HeaderFooterType.Primary)
  21. Dim p = footer.Body.Paragraphs.Add("Residential Homes | Commercial Properties | Investment Real Estate | Financing Specialists")
  22. p.Format.Alignment = ParagraphAlignment.Center
  23. p.GetRange().Runs.First.Font.Size = 8.5F
  24.  
  25. Dim sr = sec.GetRange()
  26. Dim t = sr.Tables.Add(1, 1)
  27. t.Format.Alignment = TableAlignment.Right
  28. t.Format.TableGrid.Add(216)
  29. t.Format.TableGrid.Add(126)
  30.  
  31. Dim c = t(0, 0)
  32. Dim cf = c.Format
  33. cf.GridSpan = 2
  34. cf.PreferredWidth.Type = PreferredWidthType.Points
  35. cf.PreferredWidth.Value = 342
  36. cf.Shading.Texture = TexturePattern.Clear
  37. cf.Shading.ForegroundPatternColor.RGB = System.Drawing.Color.Empty
  38. cf.Shading.BackgroundPatternColor.RGB = System.Drawing.Color.FromArgb(255, 59, 19, 110)
  39. cf.VerticalAlignment = CellVerticalAlignment.Center
  40.  
  41. Dim cp = cf.Padding
  42. cp.Top = 12
  43. cp.Left = 12
  44. cp.Bottom = 24
  45. cp.Right = 24
  46.  
  47. Dim cr = c.GetRange()
  48. p = cr.Paragraphs.First
  49. p.Format.Alignment = ParagraphAlignment.Right
  50. Dim f = p.Mark.Font
  51. f.Color.RGB = Color.Empty
  52. f.Name = "Arial"
  53. f.Size = 14
  54.  
  55. Dim r = p.GetRange().Runs.Add("Nancy Davolio")
  56. f = r.Font
  57. f.Color.RGB = Color.Empty
  58. f.Name = "Arial"
  59. f.Size = 14
  60.  
  61. p = cr.Paragraphs.Add("Chief Procurement Officer")
  62. p.Format.Alignment = ParagraphAlignment.Right
  63. f = p.Mark.Font
  64. f.Color.RGB = Color.Empty
  65. f.Name = "Arial"
  66.  
  67. r = p.GetRange().Runs.First
  68. f = r.Font
  69. f.Color.RGB = Color.Empty
  70. f.Name = "Arial"
  71.  
  72. Dim row = t.Rows.Add()
  73. row.Format.Height = 92.4F
  74.  
  75. c = row.Cells.Add()
  76. cf = c.Format
  77. cf.PreferredWidth.Type = PreferredWidthType.Points
  78. cf.PreferredWidth.Value = 216
  79. cf.Shading.Texture = TexturePattern.Clear
  80. cf.Shading.ForegroundPatternColor.RGB = System.Drawing.Color.Empty
  81. cf.Shading.BackgroundPatternColor.RGB = System.Drawing.Color.FromArgb(255, 242, 242, 242)
  82. cf.Padding.Top = 12
  83.  
  84. cr = c.GetRange()
  85. p = cr.Paragraphs.First
  86. f = p.Mark.Font
  87. f.Color.RGB = System.Drawing.Color.FromArgb(255, 196, 89, 17)
  88. f.Color.ThemeColor = ThemeColorId.Accent2
  89. f.Color.ThemeShade = 191
  90. f.Name = "Arial"
  91.  
  92. r = p.GetRange().Runs.Add("555-543-5432")
  93. f = r.Font
  94. f.Color.RGB = System.Drawing.Color.FromArgb(255, 196, 89, 17)
  95. f.Color.ThemeColor = ThemeColorId.Accent2
  96. f.Color.ThemeShade = 191
  97. f.Name = "Arial"
  98.  
  99. p = cr.Paragraphs.Add("www.acmeinc.com")
  100. p.Mark.Style = doc.Styles(BuiltInStyleId.Hyperlink)
  101. p.Mark.Font.Name = "Arial"
  102.  
  103. r = p.GetRange().Runs.First
  104. r.Style = doc.Styles(BuiltInStyleId.Hyperlink)
  105. r.Font.Name = "Arial"
  106.  
  107. p = cr.Paragraphs.Add("5432 Street West, Townsvilla, State 54321")
  108. p.Mark.Font.Name = "Arial"
  109. p.GetRange().Runs.First.Font.Name = "Arial"
  110.  
  111. c = row.Cells.Add()
  112. cf = c.Format
  113. cf.PreferredWidth.Type = PreferredWidthType.Points
  114. cf.PreferredWidth.Value = 126
  115. cf.Padding.Bottom = 0
  116. cf.VerticalAlignment = CellVerticalAlignment.Center
  117.  
  118. p = c.GetRange().Paragraphs.First
  119. p.Format.Alignment = ParagraphAlignment.Center
  120. r = p.GetRange().Runs.Add()
  121.  
  122. Dim bytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "nancy.png"))
  123. Dim pic = r.GetRange().Pictures.Add(bytes, "image/png")
  124. pic.Size.Height.Value = 96
  125. pic.Size.Width.Value = 111.75F
  126.  
  127. p = sr.Paragraphs.Add()
  128. r = p.GetRange().Runs.Add()
  129.  
  130. bytes = File.ReadAllBytes(Path.Combine("Resources", "ImagesBis", "acme.png"))
  131. pic = r.GetRange().Pictures.Add(bytes, "image/png")
  132. pic.Size.Height.Value = 63
  133. pic.Size.Width.Value = 93.75F
  134. Dim wf = pic.WrapFormat
  135. wf.Type = WrapType.Square
  136. wf.Side = WrapSide.Right
  137. wf.DistanceLeft = 9
  138. wf.DistanceRight = 9
  139.  
  140. Dim hp = pic.Position.Horizontal
  141. hp.Type = ShapePositionType.Points
  142. hp.RelativeTo = ShapeHorizontalRelativePosition.Column
  143. hp.Offset = 6
  144.  
  145. Dim vp = pic.Position.Vertical
  146. vp.Type = ShapePositionType.Points
  147. vp.RelativeTo = ShapeVerticalRelativePosition.Paragraph
  148. vp.Offset = -170.85F
  149.  
  150. AddPara(sr, Nothing)
  151. AddPara(sr, "Dear Mark,")
  152. AddPara(sr, Nothing)
  153. AddPara(sr, "The first shipment of equipment from AMA Ltd has arrived. We are delighted with every piece. Therefore, we decided to make our initial purchase larger than anticipated. I am attaching our purchase order No. 8393 for additional goods. ")
  154. AddPara(sr, Nothing)
  155. AddPara(sr, "Since you already have a copy of our Procurement Guidelines, I shall not attach them to this order. Please inform me of shipping dates.")
  156. AddPara(sr, Nothing)
  157. AddPara(sr, "Sincerely,")
  158. AddPara(sr, "Nancy Davolio,")
  159. AddPara(sr, "Chief Procurement Officer")
  160. '' Done:
  161. Return doc
  162. End Function
  163.  
  164. Private Sub AddPara(ByVal rng As Range, ByVal text As String)
  165. Dim p As Paragraph = Nothing
  166. If text IsNot Nothing Then
  167. p = rng.Paragraphs.Add(text)
  168. Else
  169. p = rng.Paragraphs.Add()
  170. End If
  171. p.Format.Spacing.LineSpacing = 1.3F
  172. p.Mark.Font.Name = "Arial"
  173. p.Mark.Font.Size = 12
  174. If text IsNot Nothing Then
  175. Dim r = p.GetRange().Runs.First
  176. r.Font.Name = "Arial"
  177. r.Font.Size = 12
  178. End If
  179. End Sub
  180. End Class
  181.