Document Solutions for Word
GrapeCity.Documents.Word Assembly / GrapeCity.Documents.Word.Templates Namespace / DataTemplate Class
Members

In This Topic
    DataTemplate Class
    In This Topic
    Provides properties and methods that are used to associate a GrapeCity.Documents.Word.GcWordDocument with template data sources, and to process data templates. See remarks for details.
    Object Model
    DataTemplate Class
    Syntax
    'Declaration
     
    Public Class DataTemplate 
    public class DataTemplate 
    Remarks
    Data templates have the form of "{{ds.value_path}[:formatter1(args1):formatter2(args2):..formatterN(argsN)]}", where
    • A user-defined name of the data source.
    • The full dot-delimited path from data source to the property name.
    • Optional: one or more formatters that process the value, see below for details.

    ## Range tags:

    Open and close tags resolve start and end of a repeating section of data. If omitted, the template engine will automatically calculate start and end of a repeating block. If 'ds' is the name of a data set:
    • Start of a range block.
    • End of a range block.
    E.g. a fully qualified template tag to list all cities in uppercase from the data source can look like this: {{#ds}}{{#ds.cities}}{{ds.cities.name}:toupper()}{{/ds.cities}}{{/ds}}

    Arrays of elementary types can be used as data sources. To address array elements, use the "value" tag. E.g. if the "ds" data source is such an array, "ds.value" will expand to the array elements' values. The following elementary types are supported: Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double, Single and String.

    Many formatters allow hiding a block of data if a certain condition is met. All such formatters have two equivalent forms - 'hide-block-if-<condition>' and the short form 'hbi-<condition>'. Conditions are self-explanatory.

    ## Range behavior modifying formatters:

    • When applied to a start range tag inside a table cell, causes the range blocks to repeat as separate paragraphs inside that single cell rather than repeating each block as a table row. Cannot be used anywhere else. The end range tag must appear inside the same cell.
    • When applied to a start range tag, causes the range blocks to repeat as runs within the same paragraph rather than separate paragraphs.

    ## Block hiding formatters:

    These formatters hide a block of data if the value in the block meets a condition.
    • hide-block-if-equals(), hbi-equals()
    • hide-block-if-greater(), hbi-greater()
    • hide-block-if-less(), hbi-less()
    • hide-block-if-contains(), hbi-contains()
    • hide-block-if-starts(), hbi-starts()
    • hide-block-if-ends(), hbi-ends()
    • hide-block-if-empty(), hbi-empty()
    • hide-block-if-not-equals(), hbi-not-equals()
    • hide-block-if-not-contains(), hbi-not-contains()
    • hide-block-if-not-starts(), hbi-not-starts()
    • hide-block-if-not-ends(), hbi-not-ends()

    ## Value formatters:

    • Default. If applied on a date, will format as short date string "d", numeric types will be formatted as "g".
    • Formats a value using the specified format string, e.g. "format(N2)".
    • Returns the specified substring of a value.
    • Returns the specified substring of a value.
    • Joins array values using the specified separator.
    • Converts a boolean to a 'yes'/'no'/'maybe' value ('maybe' is optional and is used if the value is null).
    • If a value is null, empty or empty array, returns 'default'.
    • Converts a value to double. If conversion fails, 'default_str' is converted. If that also fails, 'default_str' itself is used.
    • Converts a value to boolean. If conversion fails, 'default_str' is converted. If that also fails, 'default_str' itself is used.

    ## String formatters:

    • The number of characters in the current string.
    • A copy of this string converted to lowercase.
    • A copy of this string converted to uppercase.
    • A copy of this string without leading and trailing whitespace characters.
    • The hash code of this string.

    ## Date and time formatters (applicable to DateTime and DateTimeOffset):

    • The date component with zeroed time.
    • The day of the month.
    • The day of the week.
    • The day of the year.
    • The hour component of the DateTime .
    • The millisecond component of this DateTime.
    • The minute component of this DateTime.
    • The month component of this DateTime.
    • The second component of this DateTime.
    • The number of ticks representing this DateTime.
    • The time of day.
    • The year component of this DateTime.
    • Adds TimeSpan to this DateTime.
    • Subtracts TimeSpane from this DateTime.
    • Converts this DateTime to a Windows file time.

    ## Date and time formatters (applicable to DateTime):

    • The hash code of this DateTime.
    • Long string date representation of this DateTime.
    • Long string time representation of this DateTime.
    • OLE Automation date representation of this DateTime.
    • Short string date representation of this DateTime.
    • Short string time representation of this DateTime.
    • Converts the value of this DateTime to a Windows file time.

    ## Image formatters:

    Image formatters convert a value to an image and insert it into the document. The value must be of one of the following types:
    • A byte array containing image data.
    • A System.IO.Stream object that can be used to read image data.
    • A System.Drawing.Image object.
    • A string that can be converted to an absolute file URI, or containing Base64-encoded image data.
    Formatters:
    • Inserts the image with the specified width and height.
    • If the image is inside a shape, it is stretched to fill the shape. Otherwise it is inserted with its original width and height.
    • Fits the image into the host shape using a specified fitting strategy.

    ## Miscellaneous formatters:

    • Gets the total number of elements in all dimensions of this array.
    • Gets the number of elements in this collection.
    • Can only be applied to a range. Restarts all nested numbered lists except the topmost one.
    • Same as restart() but restarts all lists including the topmost one.
    • Can only be applied to a range. Gives this range a unique name 'id'. Allows following it using the 'follow' formatter.
    • Can only be applied to a range. Makes this range follow the named sequence 'id'.
    • Gets the number of elements in this collection.
    Inheritance Hierarchy

    System.Object
       GrapeCity.Documents.Word.Templates.DataTemplate

    See Also