DataTplUseCases.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 System.Text
  8. Imports System.Data
  9. Imports System.Linq
  10. Imports System.Globalization
  11. Imports GrapeCity.Documents.Word
  12.  
  13. '' The code in this example loads a DOCX document (created in MS Word)
  14. '' containing a report template, and depending on the selected demo,
  15. '' either adds a data source and generates the data bound report,
  16. '' or simply returns the unmodified template for reference.
  17. Public Class DataTplUseCases
  18. Public Function CreateDocx(ByRef sampleParams As String()) As GcWordDocument
  19. Dim doc = New GcWordDocument()
  20.  
  21. '' Load the template DOCX
  22. doc.Load(Path.Combine("Resources", "WordDocs", sampleParams(3)))
  23.  
  24. Using ds = New DataSet()
  25. '' Load the data set:
  26. ds.ReadXml(Path.Combine("Resources", "data", "DsWordTplDataSet.xml"))
  27.  
  28. '' Return the unmodified template document for reference
  29. If sampleParams.Length >= 6 AndAlso sampleParams(5) = "template" Then
  30. Return doc
  31. End If
  32.  
  33. '' Add the data source to the data template data sources
  34. If sampleParams.Length >= 5 AndAlso Not String.IsNullOrEmpty(sampleParams(4)) Then
  35. doc.DataTemplate.DataSources.Add("ds", ds.Tables(sampleParams(4)))
  36. Else
  37. doc.DataTemplate.DataSources.Add("ds", ds)
  38. End If
  39.  
  40. '' The document already has all the necessary bindings,
  41. '' so we only need to process the data template:
  42. doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
  43. End Using
  44.  
  45. '' Done
  46. Return doc
  47. End Function
  48.  
  49. Public Function CreateDocx(Optional parsIdx As Integer = 0) As GcWordDocument
  50. Return CreateDocx(GetSampleParamsList()(parsIdx))
  51. End Function
  52.  
  53. Public Shared Function GetSampleParamsList() As List(Of String())
  54. '' Mandatory: name, description, info
  55. '' Custom: template DOCX [[, table] , "template"]
  56. Return New List(Of String()) From
  57. {
  58. New String() {"@use-data-tpl/Lease Agreement", "Generate a lease agreement", Nothing,
  59. "Lease_Agreement_Template.docx", "LeaseAgreement"},
  60. New String() {"@use-data-tpl/Consulting Agreement", "Generate a consultancy agreement", Nothing,
  61. "Consulting_Agreement_Template.docx", "ConsAgreement"},
  62. New String() {"@use-data-tpl/Rental Agreement", "Generate a house rental agreement", Nothing,
  63. "House_Rental_Template.docx", "HouseRentalAgreement"},
  64. New String() {"@use-data-tpl/Employment Contract", "Generate an employment contract", Nothing,
  65. "Employment_Contract_Template.docx", "EmploymentContract"},
  66. New String() {"@use-data-tpl-src/Lease Agreement", "Template Lease_Agreement_Template.docx", Nothing,
  67. "Lease_Agreement_Template.docx", Nothing, "template"},
  68. New String() {"@use-data-tpl-src/Consulting Agreement", "Template Consulting_Agreement_Template.docx", Nothing,
  69. "Consulting_Agreement_Template.docx", Nothing, "template"},
  70. New String() {"@use-data-tpl-src/Rental Agreement", "Template House_Rental_Template.docx", Nothing,
  71. "House_Rental_Template.docx", Nothing, "template"},
  72. New String() {"@use-data-tpl-src/Employment Contract", "Template Employment_Contract_Template.docx", Nothing,
  73. "Employment_Contract_Template.docx", Nothing, "template"},
  74. New String() {"@use-data-tpl-src/Order Invoice", "Template InvoiceTemplate.docx", Nothing,
  75. "InvoiceTemplate.docx", Nothing, "template"},
  76. New String() {"@use-data-tpl-src/Closing Disclosure", "Template Closing_Disclosure_Template.docx", Nothing,
  77. "Closing_Disclosure_Template.docx", Nothing, "template"},
  78. New String() {"@use-data-tpl-src/Vacation Itinerary", "Template Vacation_Itinerary_Template.docx", Nothing,
  79. "Vacation_Itinerary_Template.docx", Nothing, "template"}
  80. }
  81. End Function
  82. End Class
  83.  
  84.