{"@attributes":{"version":"2.0"},"channel":{"title":"Documentation \u2013 Template Syntax in Java","link":"https:\/\/docs.aspose.com\/words\/java\/template-syntax\/","description":"Recent content in Template Syntax in Java on Documentation","generator":"Hugo -- gohugo.io","language":"en","item":[{"title":"Java: Composing Expressions in Java","link":"https:\/\/docs.aspose.com\/words\/java\/composing-expressions\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/composing-expressions\/","description":"\n        \n        \n        <p><em>Expression<\/em> is a central concept of the template syntax. Every tag is bound with an expression that is evaluated during runtime, and its result is used by LINQ Reporting Engine according to the tag&rsquo;s role.<\/p>\n<p>Expressions are composed of operands and operators according to <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=7029\">C# Language Specification 5.0<\/a> with several restrictions. See the following sections for more information.<\/p>\n<p>The complexity of expressions in templates is not restricted in any way. However, to keep your templates less cumbersome and to satisfy <a href=\"https:\/\/en.wikipedia.org\/wiki\/Separation_of_concerns\">Separation of Concerns<\/a> and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Single-responsibility_principle\">Single Responsibility<\/a> principles, locate any complex logic at the business layer of your application, rather than the templates.<\/p>\n<p><strong>This section includes the following topics:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/using-lexical-tokens\/\">Using Lexical Tokens<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-types\/\">Working with Types<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/accessing-type-members\/\">Accessing Type Members<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/using-extension-methods\/\">Using Extension Methods<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/using-operators\/\">Using Operators<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/using-lambda-functions\/\">Using Lambda Functions<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-traditional-mail-merge-data-sources\/\">Working with Traditional Mail Merge Data Sources<\/a><\/li>\n<\/ul>\n\n      "},{"title":"Java: Outputting Expression Results in Java","link":"https:\/\/docs.aspose.com\/words\/java\/outputting-expression-results\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/outputting-expression-results\/","description":"\n        \n        \n        <p>You can output expression results to your reports using expression tags. An expression tag denotes a placeholder for an expression result within a template. While building a report, the corresponding expression is evaluated, and this placeholder is replaced with the formatted result of the expression.<\/p>\n<p>An expression tag has no name and consists of the following elements:<\/p>\n<ul>\n<li>An expression enclosed by brackets<\/li>\n<li>An optional format string enclosed by double quotes and preceded by the &ldquo;:&rdquo; character<\/li>\n<li>An optional <code>html<\/code> switch<\/li>\n<\/ul>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[expression]:&#34;format&#34; -html&gt;&gt;<\/code><\/pre><\/div>\n<p>If <code>html<\/code> switch is not present, the result of the corresponding expression is written to a document as a plain text at runtime. Font attributes are derived from the first character of the corresponding tag in this case.<\/p>\n<p>If <code>html<\/code> switch is present, the expression result is considered to be a HTML block and is written as such. This feature is useful, when you need to format text parts of an expression result in different ways. For example, the following tag is replaced with a content like &ldquo;<strong>Bold<\/strong> and <em>italic<\/em> text&rdquo; at runtime.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[&#34;<span class=\"nt\">&lt;b&gt;<\/span>Bold<span class=\"nt\">&lt;\/b&gt;<\/span> and <span class=\"nt\">&lt;i&gt;<\/span>italic<span class=\"nt\">&lt;\/i&gt;<\/span> text&#34;] -html&gt;&gt;<\/code><\/pre><\/div>\n<p>To format a numeric or date-time expression result, you can specify a format string as an element of the corresponding expression tag. Such format strings are the same as the ones that you pass to <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/text\/DecimalFormat.html\">DecimalFormat<\/a> or <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/text\/SimpleDateFormat.html\">SimpleDateFormat<\/a> constructors. That is, for example, given that <code>d<\/code> is a <code>Date<\/code> value, you can use the following template to format the value using the &ldquo;yyyy.MM.dd&rdquo; pattern.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[d]:&#34;yyyy.MM.dd&#34;&gt;&gt;<\/code><\/pre><\/div>\n<p>LINQ Reporting Engine provides several additional number formats that can not be specified using format strings because these formats are missing in standard  <code>REF<\/code> platform Java libraries. The following table describes these formats.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">Number Format<\/th>\n<th style=\"text-align:left\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\"><strong>alphabetic<\/strong><\/td>\n<td style=\"text-align:left\">Formats an integer number as an upper-case letter (A, B, C, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>roman<\/strong><\/td>\n<td style=\"text-align:left\">Formats an integer number as an upper-case Roman numeral (I, II, III, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>ordinal<\/strong><\/td>\n<td style=\"text-align:left\">Appends an ordinal suffix to an integer number (1st, 2nd, 3rd, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>ordinalText<\/strong><\/td>\n<td style=\"text-align:left\">Converts an integer number to its ordinal text representation (First, Second, Third, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>cardinal<\/strong><\/td>\n<td style=\"text-align:left\">Converts an integer number to its text representation (One, Two, Three, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>hex<\/strong><\/td>\n<td style=\"text-align:left\">Formats an integer number as hexadecimal (8, 9, A, B, C, D, E, F, 10, 11, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>arabicDash<\/strong><\/td>\n<td style=\"text-align:left\">Encloses an integer number with dashes (- 1 -, - 2 -, - 3 -, &hellip;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>dollarText<\/strong><\/td>\n<td style=\"text-align:left\">Converts a numeric value to its text representation with its fraction as Arabic numerators over 100 (for example, one thousand two hundred thirty-four and 56\/100)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can specify one of these additional number formats instead of a format string like in the following example. Given that <code>i<\/code> is an integer number, you can format the number as an upper-case letter using the following template.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[i]:alphabetic&gt;&gt;<\/code><\/pre><\/div>\n<p>LINQ Reporting Engine provides several additional string formats that can not be specified using format strings because these formats are missing in standard  <code>REF<\/code> platform Java libraries. The following table describes these formats.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">String Format<\/th>\n<th style=\"text-align:left\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\"><strong>lower<\/strong><\/td>\n<td style=\"text-align:left\">Converts a string to lower case (&ldquo;the string&rdquo;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>upper<\/strong><\/td>\n<td style=\"text-align:left\">Converts a string to upper case (&ldquo;THE STRING&rdquo;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>caps<\/strong><\/td>\n<td style=\"text-align:left\">Capitalizes a first letter of every word in a string (&ldquo;The String&rdquo;)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>firstCap<\/strong><\/td>\n<td style=\"text-align:left\">Capitalizes the first letter of the first word in a string (&ldquo;The string&rdquo;)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can specify one of these additional string formats instead of a format string like in the following example. Given that <code>s<\/code> is a string, you can capitalize a first letter of every word in the string using the following template.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[s]:caps&gt;&gt;<\/code><\/pre><\/div>\n<p>You can also specify one of the additional string formats together with a format string or an additional number format like in the following examples. Given that <code>d<\/code> is a <code>Date<\/code> value, you can convert its textual month representation to upper case using the following template.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[d]:&#34;MMMM&#34;:upper&gt;&gt;<\/code><\/pre><\/div>\n<p>Given that <code>i<\/code> is an integer number, you can convert the number to a lower-case Roman numeral using the following template.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-xml\" data-lang=\"xml\"><span class=\"err\">&lt;&lt;<\/span>[i]:roman:lower&gt;&gt;<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 In contrast to format strings, additional number and string formats must not be enclosed with double quotes.<\/p>\n\n      "},{"title":"Java: Outputting Sequential Data in Java","link":"https:\/\/docs.aspose.com\/words\/java\/outputting-sequential-data\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/outputting-sequential-data\/","description":"\n        \n        \n        <p>You can output a sequence of elements of the same type to your report using a <em>data band<\/em>. A data band has a body that represents a template for a single element of such a sequence. While building a report, sequence elements are enumerated, and the following procedure takes place for each of the elements:<\/p>\n<ol>\n<li>The data band body is duplicated and appended to the report.<\/li>\n<li>The appended data band body is populated with the element\u2019s data.<\/li>\n<\/ol>\n<p><strong>Note<\/strong> \u2013 A data band body can contain nested data bands.<\/p>\n<p>A data band body is defined between the corresponding opening and closing <code>foreach<\/code> tags within a template as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">...&gt;&gt;<\/span>\n<span class=\"n\">data_band_body<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>You can reference an element of the corresponding sequence in template expressions within a data band body using an iteration variable. At runtime, an iteration variable represents a sequence element for which an iteration is currently being performed. You can declare an iteration variable within the corresponding opening <code>foreach<\/code> tag.<\/p>\n<p>An opening <code>foreach<\/code> tag defines a <code>foreach<\/code> statement enclosed by brackets. The following table describes elements of this statement.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">Element<\/th>\n<th style=\"text-align:left\">Optional?<\/th>\n<th style=\"text-align:left\">Remarks<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\"><strong>Iteration Variable Type<\/strong><\/td>\n<td style=\"text-align:left\">Yes<\/td>\n<td style=\"text-align:left\">You can specify the type of an iteration variable explicitly. This type must be known by the engine (see &ldquo;Setting up Known External Types&rdquo; for more information).<br>If you do not specify the type explicitly, it is determined implicitly by the engine depending on the type of the corresponding sequence.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Iteration Variable Name<\/strong><\/td>\n<td style=\"text-align:left\">Yes<\/td>\n<td style=\"text-align:left\">You can specify the name of an iteration variable to use it while accessing the variable\u2019s members. The name must be unique within the scope of the corresponding <code>foreach<\/code> tag.<br>If you do not specify the name, you can access the variable&rsquo;s members using the contextual object member access syntax (see &ldquo;Using Contextual Object Member Access&rdquo; for more information).<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>&ldquo;in&rdquo; Keyword<\/strong><\/td>\n<td style=\"text-align:left\">No<\/td>\n<td style=\"text-align:left\"><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Sequence Expression<\/strong><\/td>\n<td style=\"text-align:left\">No<\/td>\n<td style=\"text-align:left\">A sequence expression must return an <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/Iterable.html\">Iterable<\/a> implementor.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The complete syntax of a <code>foreach<\/code> tag (including optional elements) is as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">variable_type<\/span> <span class=\"n\">variable_name<\/span> <span class=\"k\">in<\/span> <span class=\"n\">sequence_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<span class=\"n\">data_band_body<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>This section includes the following topics:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-common-data-bands\/\">Working with Common Data Bands<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-table-row-data-bands\/\">Working with Table-Row Data Bands<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-table-column-data-bands\/\">Working with Table-Column Data Bands<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-cross-pivot-tables\/\">Working with Cross (Pivot) Tabless<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/using-extension-methods-of-iteration-variables\/\">Using Extension Methods of Iteration Variables<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/using-charts-to-represent-sequential-data\/\">Using Charts to Represent Sequential Data<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/forcing-movement-to-next-item-within-data-band\/\">Forcing Movement to Next Item within Data Band<\/a><\/li>\n<\/ul>\n\n      "},{"title":"Java: Using Conditional Blocks in Java","link":"https:\/\/docs.aspose.com\/words\/java\/using-conditional-blocks\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/using-conditional-blocks\/","description":"\n        \n        \n        <p>You can use different document blocks to represent the same data depending on a condition with the help of conditional blocks. A <em>conditional block<\/em> represents a set of template options, each of which is bound with a conditional expression. At runtime, these conditional expressions are sequentially evaluated, until an expression that returns <code>true<\/code> is reached. Then, the conditional block is replaced with the corresponding template option populated with data.<\/p>\n<p>A conditional block can have a default template option that is not bound with a conditional expression. At runtime, this template option is used, when none of conditional expressions return <code>true<\/code>. If a default template option is missing and none of conditional expressions return `true, then the whole conditional block is removed during runtime.<\/p>\n<p>You can use the following syntax to declare a conditional block.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">if<\/span> <span class=\"p\">[<\/span><span class=\"n\">conditional_expression1<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<span class=\"n\">template_option1<\/span>\n<span class=\"p\">&lt;&lt;<\/span><span class=\"n\">elseif<\/span> <span class=\"p\">[<\/span><span class=\"n\">conditional_expression2<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<span class=\"n\">template_option2<\/span>\n<span class=\"p\">...<\/span>\n<span class=\"p\">&lt;&lt;<\/span><span class=\"k\">else<\/span><span class=\"p\">&gt;&gt;<\/span>\n<span class=\"n\">default_template_option<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">if<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 A conditional expression must return a <code>Boolean<\/code> value.<\/p>\n<p><strong>This section includes the following topics:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-common-conditional-blocks\/\">Working with Common Conditional Blocks<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-table-row-conditional-blocks\/\">Working with Table-Row Conditional Blocks<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-table-column-conditional-blocks\/\">Working with Table-Column Conditional Blocks<\/a><\/li>\n<\/ul>\n\n      "},{"title":"Java: Inserting Documents Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/inserting-documents-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/inserting-documents-dynamically\/","description":"\n        \n        \n        <p>You can insert contents of outer documents to your reports dynamically using <code>doc<\/code> tags. A <code>doc<\/code> tag denotes a placeholder within a template for a document to be inserted during runtime.<\/p>\n<p>Syntax of a <code>doc<\/code> tag is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">doc<\/span> <span class=\"p\">[<\/span><span class=\"n\">document_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 A <code>doc<\/code> tag can be used almost anywhere in a template document except textboxes and charts.<\/p>\n<p>An expression declared within a <code>doc<\/code> tag is used by the engine to load a document to be inserted during runtime. The expression must return a value of one of the following types:<\/p>\n<ul>\n<li>A byte array containing document data<\/li>\n<li>An <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/io\/InputStream.html\">InputStream<\/a> instance able to read document data<\/li>\n<li>An instance of the <code>Document<\/code> class<\/li>\n<li>A string containing a document URI, path, or Base64-encoded document data<\/li>\n<\/ul>\n<p>While building a report, an expression declared within a <code>doc<\/code> tag is evaluated and its result is used to load a document which content replaces the <code>doc<\/code> tag then.<\/p>\n<p><strong>Note<\/strong> \u2013 If an expression declared within a <code>doc<\/code> tag returns a stream object, then the stream is closed by the engine as soon as a corresponding document is loaded.<\/p>\n<p>By default, while inserting content of an outer document, the engine applies corresponding styles of a template document. This makes content of a result document look more consistent. However, you can keep source formatting for content being inserted by using a <code>sourceStyles<\/code> switch as shown in the following snippet.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">doc<\/span> <span class=\"p\">[<\/span><span class=\"n\">document_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">sourceStyles<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>The engine exhibits similar behavior when dealing with list numbering. By default, numbered lists from a template document are continued when their identifiers match those from a document being inserted. However, if numbering for content being inserted should be separated and kept as is, this can be done by applying a <code>sourceNumbering<\/code> switch as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">doc<\/span> <span class=\"p\">[<\/span><span class=\"n\">document_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">sourceNumbering<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Also, you can trim the last paragraph break from a document being inserted by using an <code>inline<\/code> switch. In particular, this feature is useful for a single-paragraph document being inserted, when it is necessary to put the document\u2019s content within the same paragraph that contains a corresponding <code>doc<\/code> tag in order to apply the paragraph\u2019s formatting such as list numbering. The following snippet shows the template syntax for this.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">doc<\/span> <span class=\"p\">[<\/span><span class=\"n\">document_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">inline<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>By default, a document being inserted is not checked against template syntax and is not populated with data. However, you can enable this by using a <code>build<\/code> switch as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">doc<\/span> <span class=\"p\">[<\/span><span class=\"n\">document_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">build<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>When a <code>build<\/code> switch is used, the engine treats a document being inserted as a template that can access the following data available at the scope of a corresponding <code>doc<\/code> tag:<\/p>\n<ul>\n<li>Data sources<\/li>\n<li>Variables<\/li>\n<li>A contextual object (see \u201cUsing Contextual Object Member Access\u201d for more information)<\/li>\n<li>Known external types (see \u201cSetting up Known External Types\u201d for more information)<\/li>\n<\/ul>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I insert a document from a file path using a <code>doc<\/code> tag?<br>\n<strong>A:<\/strong> Place a <code>doc<\/code> tag in the template and provide the file path as a string expression, e.g. <code>&lt;&lt;doc [&quot;C:\/Docs\/Appendix.docx&quot;]&gt;&gt;<\/code>. At runtime the engine loads the file and replaces the tag with its content.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> I want the inserted document to keep its original formatting. Which switch should I use?<br>\n<strong>A:<\/strong> Add the <code>-sourceStyles<\/code> switch to the tag: <code>&lt;&lt;doc [docExpression] -sourceStyles&gt;&gt;<\/code>. This tells the engine to preserve the source document\u2019s styles instead of mapping them to the template\u2019s styles.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> My inserted document contains numbered lists, but the numbering continues from the template list. How can I keep the numbering separate?<br>\n<strong>A:<\/strong> Use the <code>-sourceNumbering<\/code> switch: <code>&lt;&lt;doc [docExpression] -sourceNumbering&gt;&gt;<\/code>. This prevents the engine from merging list identifiers and retains the original numbering of the inserted document.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I insert a single\u2011paragraph document inline so that it adopts the surrounding paragraph\u2019s formatting?<br>\n<strong>A:<\/strong> Yes. Apply the <code>-inline<\/code> switch: <code>&lt;&lt;doc [docExpression] -inline&gt;&gt;<\/code>. The engine removes the trailing paragraph break of the inserted document and places its text inside the same paragraph that contains the tag.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I populate merge fields inside the inserted document with data from my report?<br>\n<strong>A:<\/strong> Add the <code>-build<\/code> switch: <code>&lt;&lt;doc [docExpression] -build&gt;&gt;<\/code>. The inserted document is treated as a template and can use the same data sources, variables, and contextual objects that are available at the location of the <code>doc<\/code> tag.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Inserting HTML Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/inserting-html-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/inserting-html-dynamically\/","description":"\n        \n        \n        <p>You can insert HTML to your reports dynamically by using one of the following two options.<\/p>\n<p>The first one is using of an expression tag with an <code>html<\/code> switch applied as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;[<\/span><span class=\"n\">html_text_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">html<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>This option is useful when you need to override formatting of some parts of an expression result, for example, highlight a word with a bold or italic font while staying consistent with styles of a template document. For more information on dynamic HTML insertion using this approach, see \u201cOutputting Expression Results\u201d.<\/p>\n<p>The second option for dynamic HTML insertion is using of an <code>html<\/code> tag. An <code>html<\/code> tag denotes a placeholder within a template for an HTML block to be inserted during runtime. Its syntax is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">html<\/span> <span class=\"p\">[<\/span><span class=\"n\">html_text_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 An <code>html<\/code> tag is forbidden within charts.<\/p>\n<p>While building a report, an expression declared within an <code>html<\/code> tag is evaluated and its result as a string is interpreted as an HTML block which content replaces the <code>html<\/code> tag then.<\/p>\n<p>In its base usage, an <code>html<\/code> tag behaves exactly the same as an expression tag with an <code>html<\/code> switch applied. In particular, it makes the engine to use corresponding styles of a template document. This makes content of a result document look more consistent. However, you can keep source HTML formatting for content being inserted (to make it look like in a browser) by using a <code>sourceStyles<\/code> switch as shown in the following snippet.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">html<\/span> <span class=\"p\">[<\/span><span class=\"n\">html_text_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">sourceStyles<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I insert HTML using an expression tag with the <code>-html<\/code> switch?<br>\n<strong>A:<\/strong> Place the expression inside double\u2011angle brackets and add the <code>-html<\/code> switch, e.g., <code>&lt;&lt;[myHtml] -html&gt;&gt;<\/code>. The engine evaluates the expression, treats the result as HTML, and inserts it while applying the template\u2019s styles.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> When should I prefer the <code>html<\/code> tag over an expression tag with <code>-html<\/code>?<br>\n<strong>A:<\/strong> Use the <code>html<\/code> tag when you want a clear placeholder in the template that will be completely replaced by the evaluated HTML at runtime. It is especially handy for larger HTML blocks or when you need the <code>sourceStyles<\/code> option.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I use the <code>html<\/code> tag inside a chart?<br>\n<strong>A:<\/strong> No. The <code>html<\/code> tag is forbidden within chart definitions. Attempting to do so will cause a runtime error. Use plain text or image placeholders inside charts instead.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I preserve the original HTML styling (fonts, colors, etc.) when inserting it?<br>\n<strong>A:<\/strong> Add the <code>-sourceStyles<\/code> switch to the <code>html<\/code> tag, e.g., <code>&lt;&lt;html [myHtml] -sourceStyles&gt;&gt;<\/code>. This tells the engine to keep the HTML\u2019s own styling rather than mapping it to the template\u2019s styles.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Inserting Images Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/inserting-images-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/inserting-images-dynamically\/","description":"\n        \n        \n        <p>You can insert images to your reports dynamically using <code>image<\/code> tags. To declare a dynamically inserted image within your template, do the following steps:<\/p>\n<ol>\n<li>Add a textbox to your template at the place where you want an image to be inserted.<\/li>\n<li>Set common image attributes such as frame, size, and others for the textbox, making the textbox look like a blank inserted image.<\/li>\n<li>Specify an <code>image<\/code> tag within the textbox using the following syntax.<\/li>\n<\/ol>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">image<\/span> <span class=\"p\">[<\/span><span class=\"n\">image_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>The expression declared within an <code>image<\/code> tag is used by the engine to build an image to be inserted. The expression must return a value of one of the following types:<\/p>\n<ul>\n<li>A byte array containing an image data<\/li>\n<li>An <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/io\/InputStream.html\">InputStream<\/a> instance able to read an image data<\/li>\n<li>A <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/awt\/image\/BufferedImage.html\">BufferedImage<\/a> object<\/li>\n<li>A string containing an image URI, path, or Base64-encoded image data<\/li>\n<\/ul>\n<p>While building a report, the following procedure is applied to an <code>image<\/code> tag:<\/p>\n<ol>\n<li>The expression declared within the tag is evaluated and its result is used to form an image.<\/li>\n<li>The corresponding textbox is filled with this image.<\/li>\n<li>The tag is removed from the textbox.<\/li>\n<\/ol>\n<p><strong>Note<\/strong> \u2013 If the expression declared within an <code>image<\/code> tag returns a stream object, then it is closed by the engine as soon as the corresponding image is built.<\/p>\n<p>By default, the engine stretches an image filling a textbox to the size of the textbox without preserving the ratio of the image. However, you can change this behavior in the following ways:<\/p>\n<ul>\n<li>To keep the size of the textbox and stretch the image within bounds of the textbox preserving the ratio of the image, use the <code>keepRatio<\/code> switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">image<\/span> <span class=\"p\">[<\/span><span class=\"n\">image_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">keepRatio<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>To keep the width of the textbox and change its height according to the ratio of the image, use the <code>fitHeight<\/code> switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">image<\/span> <span class=\"p\">[<\/span><span class=\"n\">image_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">fitHeight<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>To keep the height of the textbox and change its width according to the ratio of the image, use the <code>fitWidth<\/code> switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">image<\/span> <span class=\"p\">[<\/span><span class=\"n\">image_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">fitWidth<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>To change the size of the textbox according to the size of the image, use the <code>fitSize<\/code> switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">image<\/span> <span class=\"p\">[<\/span><span class=\"n\">image_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">fitSize<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>To change the size of the textbox according to the size of the image without increasing the size of the textbox, use the <code>fitSizeLim<\/code> switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">image<\/span> <span class=\"p\">[<\/span><span class=\"n\">image_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">-<\/span><span class=\"n\">fitSizeLim<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<\/ul>\n<p><strong>Note<\/strong> \u2013 If the size of the image is greater than the size of the textbox, then the <code>fitSizeLim<\/code> switch acts like <code>fitHeight<\/code> or <code>fitWidth<\/code>. Otherwise, the <code>fitSizeLim<\/code> switch acts like <code>fitSize<\/code>.<\/p>\n\n      "},{"title":"Java: Inserting Bookmarks Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/inserting-bookmarks-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/inserting-bookmarks-dynamically\/","description":"\n        \n        \n        <p>You can insert bookmarks to your reports dynamically using <code>bookmark<\/code> tags. Syntax of a <code>bookmark<\/code> tag is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">bookmark<\/span> <span class=\"p\">[<\/span><span class=\"n\">bookmark_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<span class=\"n\">bookmarked_content<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">bookmark<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Here, <code>bookmark_expression<\/code> defines the name of a bookmark to be inserted during runtime. This expression is mandatory and must return a non\u2011empty value. While building a report, <code>bookmark_expression<\/code> is evaluated and its result is used to construct a bookmark start and end that replace corresponding opening and closing <code>bookmark<\/code> tags respectively.<\/p>\n<p><strong>Note<\/strong> \u2013 A <code>bookmark<\/code> tag cannot be used within a chart.<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I generate the bookmark name at runtime?<br>\n<strong>A:<\/strong> Use any valid expression that returns a string, such as a field from your data source or a concatenation of values. For example: <code>&lt;&lt;bookmark [\\&quot;Section_\\&quot; + data[\\&quot;Id\\&quot;]]&gt;&gt;<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can a <code>bookmark<\/code> tag be placed inside a table cell?<br>\n<strong>A:<\/strong> Yes, the <code>bookmark<\/code> tag works inside tables, paragraphs, and most other document elements. The only restriction is that it cannot be used inside a chart.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I reference a dynamically created bookmark later in the document?<br>\n<strong>A:<\/strong> After the report is generated, you can retrieve the bookmark by its runtime name using <code>Document.getBookmarks().get(\\&quot;BookmarkName\\&quot;)<\/code>. Ensure the name you generated is stored or predictable so you can access it later.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What happens if the bookmark expression evaluates to an empty string?<br>\n<strong>A:<\/strong> The engine will throw an error because a bookmark name is required and cannot be empty. Always validate that the expression returns a non\u2011empty value before the tag is processed.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to create multiple bookmarks with the same name?<br>\n<strong>A:<\/strong> No. Bookmark names must be unique within a document. If you attempt to insert a duplicate name, Aspose.Words will replace the existing bookmark, potentially causing loss of the original bookmark\u2019s range. Use distinct names for each bookmark.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Inserting Hyperlinks Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/inserting-hyperlinks-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/inserting-hyperlinks-dynamically\/","description":"\n        \n        \n        <p>You can insert hyperlinks to your reports dynamically using <code>link<\/code> tags. Syntax of a <code>link<\/code> tag is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">link<\/span> <span class=\"p\">[<\/span><span class=\"n\">uri_or_bookmark_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">[<\/span><span class=\"n\">display_text_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Here, <code>uri_or_bookmark_expression<\/code> defines URI or the name of a bookmark within the same document for a hyperlink to be inserted dynamically. This expression is mandatory and must return a non\u2011empty value.<\/p>\n<p>In turn, <code>display_text_expression<\/code> defines text to be displayed for the hyperlink. This expression is optional. If it is omitted or returns an empty value, then during runtime, a value of <code>uri_or_bookmark_expression<\/code> is used as display text as well.<\/p>\n<p><strong>Note<\/strong> \u2013 Values of both <code>uri_or_bookmark_expression<\/code> and <code>display_text_expression<\/code> can be of any types. During runtime, <code>Object.toString()<\/code> is invoked to get textual representations of these expressions\u2019 values, which is useful for expressions of types like <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/net\/URI.html\">URI<\/a>, for example.<\/p>\n<p>While building a report, <code>uri_or_bookmark_expression<\/code> and <code>display_text_expression<\/code> are evaluated and their results are used to construct a hyperlink that replaces the corresponding <code>link<\/code> tag then. If <code>uri_or_bookmark_expression<\/code> returns the name of a bookmark in the same document, then the hyperlink navigates to the bookmark. Otherwise, the hyperlink navigates to a corresponding external resource.<\/p>\n<p><strong>Note<\/strong> \u2013 A <code>link<\/code> tag cannot be used within a chart.<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I create a hyperlink that points to an external URL?<br>\n<strong>A:<\/strong> Use the <code>link<\/code> tag with the URL as the first argument, e.g., <code>&lt;&lt;link &quot;https:\/\/example.com&quot; &quot;Visit Example&quot;&gt;&gt;<\/code>. The URL expression can be a string literal, a variable, or any object whose <code>toString()<\/code> returns a valid URI.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I link to a bookmark inside the same document?<br>\n<strong>A:<\/strong> Yes. Provide the bookmark name as the <code>uri_or_bookmark_expression<\/code>, for example <code>&lt;&lt;link &quot;MyBookmark&quot; &quot;Go to Section&quot;&gt;&gt;<\/code>. At runtime the tag creates a hyperlink that navigates to the bookmark named <em>MyBookmark<\/em>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What happens if I omit the display\u2011text expression?<br>\n<strong>A:<\/strong> When the second argument is omitted or evaluates to an empty value, Aspose.Words uses the string representation of the first argument (the URI or bookmark name) as the visible text of the hyperlink.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to use a <code>link<\/code> tag inside a chart?<br>\n<strong>A:<\/strong> No. The <code>link<\/code> tag is not supported inside chart elements. Attempting to do so will cause the tag to be ignored or raise an error during report generation. Place the tag in regular paragraphs or tables instead.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Content Controls in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-content-controls\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-content-controls\/","description":"\n        \n        \n        <p>LINQ Reporting Engine enables you to perform certain operations on content controls dynamically while building a report.<\/p>\n<p><strong>Note<\/strong> \u2013 To work with content controls in template documents using Microsoft Word\u00ae, you may need to <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/vsto\/how-to-show-the-developer-tab-on-the-ribbon?view=vs-2022\">show the Developer tab on its ribbon<\/a>.<\/p>\n<h2 id=\"setting-checkbox-value-dynamically\">Setting Checkbox Value Dynamically<\/h2>\n<p>You can set checkbox values to either checked or unchecked in your reports dynamically by taking the following steps:<\/p>\n<ol>\n<li>Add a checkbox content control to your template at a place where you want it to appear in a result document.<\/li>\n<li>By editing content control properties, add a check tag to the title of the checkbox content control using the following syntax.<\/li>\n<\/ol>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">check<\/span> <span class=\"p\">[<\/span><span class=\"n\">conditional_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Here, <code>conditional_expression<\/code> defines a condition upon which the value of the checkbox content control is to be set to checked (or unchecked, if the condition is not met). The conditional expression must return a <code>Boolean<\/code> value.<\/p>\n<p>While building a report, a conditional expression declared within a <code>check<\/code> tag is evaluated and the value of its containing checkbox content control is set accordingly. The <code>check<\/code> tag itself is removed then.<\/p>\n<h2 id=\"adding-combobox-and-dropdown-list-items-dynamically\">Adding Combobox and Dropdown List Items Dynamically<\/h2>\n<p>You can dynamically add items to comboboxes and dropdown lists defined in your template by taking the following steps:<\/p>\n<ol>\n<li>Add a combobox or dropdown list content control to your template at a place where you want it to appear in a result document.<\/li>\n<li>By editing content control properties, add an <code>item<\/code> tag to the title of this content control using the following syntax.<\/li>\n<\/ol>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">item<\/span> <span class=\"p\">[<\/span><span class=\"n\">value_expression<\/span><span class=\"p\">]<\/span> <span class=\"p\">[<\/span><span class=\"n\">display_name_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Here, <code>value_expression<\/code> defines a value of a combobox or dropdown list item to be added dynamically. This expression is mandatory and must return a non\u2011empty value.<\/p>\n<p>In turn, <code>display_name_expression<\/code> defines a display name of the combobox or dropdown list item to be added. This expression is optional. If it is omitted, then during runtime, a value of <code>value_expression<\/code> is used as a display name as well.<\/p>\n<p><strong>Note<\/strong> \u2013 Values of both <code>value_expression<\/code> and <code>display_name_expression<\/code> can be of any types. During runtime, <code>Object.toString()<\/code> is invoked to get textual representations of these expressions\u2019 values.<\/p>\n<p>While building a report, <code>value_expression<\/code> and <code>display_name_expression<\/code> are evaluated and a corresponding combobox or dropdown list item is added. A declaring <code>item<\/code> tag is removed then.<\/p>\n<p>A single <code>item<\/code> tag causes addition of a single combobox or dropdown list item during runtime. You can add multiple combobox or dropdown list items using multiple <code>item<\/code> tags as shown in the following snippet.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">item<\/span> <span class=\"p\">...&gt;&gt;&lt;&lt;<\/span><span class=\"n\">item<\/span> <span class=\"p\">...&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Also, you can normally use <code>item<\/code> tags within data bands to add a combobox or dropdown list item per item of a data collection. For example, given that <code>clients<\/code> is a <code>DataTable<\/code> instance having a field named \u201cName\u201d, you can use the following template to cover such a scenario.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">client<\/span> <span class=\"k\">in<\/span> <span class=\"n\">clients<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;<\/span><span class=\"n\">item<\/span> <span class=\"p\">[<\/span><span class=\"n\">client<\/span><span class=\"p\">.<\/span><span class=\"n\">Name<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>An <code>item<\/code> tag can also be combined with an <code>if<\/code> tag to add a combobox or dropdown list item depending on a condition as shown in the following snippet.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">if<\/span> <span class=\"p\">...&gt;&gt;&lt;&lt;<\/span><span class=\"n\">item<\/span> <span class=\"p\">...&gt;&gt;&lt;&lt;\/<\/span><span class=\"k\">if<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Existing combobox and dropdown list items are not affected by <code>item<\/code> tags. Thus, you can combine both ways of adding combobox and dropdown list items using a template: static and dynamic.<\/p>\n<p><strong>Note<\/strong> \u2013 While inserting a combobox or dropdown list, Microsoft Word adds a default item that has to be removed manually, if the item is unwanted.<\/p>\n<h2 id=\"setting-content-control-titles-dynamically\">Setting Content Control Titles Dynamically<\/h2>\n<p>You can normally use common expression tags in content control titles, thus forming their contents dynamically. For example, given that <code>s<\/code> is a string value, you can set a content control title from this value dynamically by putting the following expression tag into the title.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;[<\/span><span class=\"n\">s<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I set a checkbox content control to checked or unchecked based on data?<br>\n<strong>A:<\/strong> Add a <code>check<\/code> tag to the checkbox title, e.g., <code>&lt;&lt;check [order.IsPaid]&gt;&gt;<\/code>. The expression must return a Boolean; if true, the checkbox is checked, otherwise it remains unchecked. The tag is removed after evaluation.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I add items to a combobox or dropdown list at runtime?<br>\n<strong>A:<\/strong> Use the <code>item<\/code> tag inside the content control title: <code>&lt;&lt;item [value] [displayName]&gt;&gt;<\/code>. Place multiple <code>item<\/code> tags or put them inside a <code>foreach<\/code> loop to add many items dynamically.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to set the title of a content control dynamically?<br>\n<strong>A:<\/strong> Yes. Insert an expression tag directly in the title, such as <code>&lt;&lt;[customer.Name]&gt;&gt;<\/code>. The expression is evaluated and the resulting string becomes the control\u2019s title.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I conditionally add a combobox item?<br>\n<strong>A:<\/strong> Combine <code>if<\/code> and <code>item<\/code> tags: <code>&lt;&lt;if [product.InStock]&gt;&gt; &lt;&lt;item [product.Id] [product.Name]&gt;&gt; &lt;&lt;endif&gt;&gt;<\/code>. The item is added only when the condition evaluates to true.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Word adds a default item to a new combobox; how do I remove it?<br>\n<strong>A:<\/strong> The default item must be removed manually in the template before processing, or you can delete it programmatically after the document is generated using the <code>ContentControl.Remove<\/code> method.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Setting Text Color Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/setting-text-color-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/setting-text-color-dynamically\/","description":"\n        \n        \n        <p>You can set a font color for text contents dynamically using <code>textColor<\/code> tags. Syntax of a <code>textColor<\/code> tag is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">textColor<\/span> <span class=\"p\">[<\/span><span class=\"n\">color_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<span class=\"n\">content_to_be_colored<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">textColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 A <code>textColor<\/code> tag can be used anywhere in a template document except charts.<\/p>\n<p>An expression declared within an opening <code>textColor<\/code> tag defines a text font color to be applied during runtime. The expression must return a value of one of the following types:<\/p>\n<ul>\n<li>A string containing the name of a known color, that is, the case-insensitive name of a member of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.drawing.knowncolor?view=net-6.0\">KnownColor<\/a> enumeration like in the following example.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\">  <span class=\"p\">&lt;&lt;<\/span><span class=\"n\">textColor<\/span> <span class=\"p\">[<\/span><span class=\"err\">\u201c<\/span><span class=\"n\">red<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">with<\/span> <span class=\"n\">red<\/span> <span class=\"n\">font<\/span><span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">textColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n  \n<\/code><\/pre><\/div><\/li>\n<li>A string containing an HTML color code like in the following example.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\">  <span class=\"p\">&lt;&lt;<\/span><span class=\"n\">textColor<\/span> <span class=\"p\">[<\/span><span class=\"err\">\u201c#<\/span><span class=\"n\">F08080<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">with<\/span> <span class=\"n\">light<\/span> <span class=\"n\">coral<\/span> <span class=\"n\">font<\/span><span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">textColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n  \n<\/code><\/pre><\/div><\/li>\n<li>An integer value defining RGB (red, green, blue) components of the color like in the following example.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\">  <span class=\"p\">&lt;&lt;<\/span><span class=\"n\">textColor<\/span> <span class=\"p\">[<\/span><span class=\"m\">0<\/span><span class=\"n\">xFFFF00<\/span><span class=\"p\">]&gt;&gt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">with<\/span> <span class=\"n\">yellow<\/span> <span class=\"n\">font<\/span><span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">textColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n  \n<\/code><\/pre><\/div><\/li>\n<li>A value of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.drawing.color?view=net-6.0\">Color<\/a> type.<\/li>\n<\/ul>\n<p>While building a report, an expression declared within an opening <code>textColor<\/code> tag is evaluated and text content between the tag and its corresponding closing tag is colored accordingly. The opening and closing <code>textColor<\/code> tags are removed then.<\/p>\n<p><strong>Note<\/strong> \u2013 Within a text block to be colored using a <code>textColor<\/code> tag, elements having a text font color already applied are not affected during runtime.<\/p>\n<p>You can use <code>textColor<\/code> tags nested into each other. Also, you can normally use <code>textColor<\/code> tags within data bands and conditional blocks like in the following example.<\/p>\n<p>Assume that you have the <code>ColoredItem<\/code> class defined in your application as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">ColoredItem<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getName<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getDescription<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">Color<\/span> <span class=\"n\">getColor<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"p\">...<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre><\/div>\n<p>Given that <code>items<\/code> is an enumeration of <code>ColoredItem<\/code> instances, you can use the following template to output every item into a separate paragraph, which text is colored dynamically.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">item<\/span> <span class=\"k\">in<\/span> <span class=\"n\">items<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;<\/span><span class=\"n\">textColor<\/span> <span class=\"p\">[<\/span><span class=\"n\">item<\/span><span class=\"p\">.<\/span><span class=\"n\">getColor<\/span><span class=\"p\">()]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">item<\/span><span class=\"p\">.<\/span><span class=\"n\">getName<\/span><span class=\"p\">()]&gt;&gt;&lt;&lt;\/<\/span><span class=\"n\">textColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>To output every item into a separate table row, which text is colored dynamically, you can use the following template.<\/p>\n<table class=\"setting-text-color-dynamically\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>&lt;&lt;foreach [item in items]>>&lt;&lt;textColor [item.getColor()]>>&lt;&lt;[item.getName()]>><\/td>\n\t\t\t<td>&lt;&lt;[item.getDescription()]>>&lt;&lt;\/textColor>>&lt;&lt;\/foreach>><\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p><strong>Note<\/strong> \u2013 Start and end <code>textColor<\/code> tags can be located either in paragraphs of a single story (or table cell) or in rows of a single document table in the same way as <code>foreach<\/code> tags.<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I specify a color using a hexadecimal HTML code in a <code>textColor<\/code> tag?<br>\n<strong>A:<\/strong> Place the hex code as a string inside the tag\u2019s expression, e.g., <code>&lt;&lt;textColor [&quot;#1E90FF&quot;]&gt;&gt;<\/code>. The engine parses the string and applies the corresponding RGB color at runtime.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to pass a <code>java.awt.Color<\/code> object returned from a method to the <code>textColor<\/code> tag?<br>\n<strong>A:<\/strong> Yes. The expression can return a <code>Color<\/code> instance, such as <code>&lt;&lt;textColor [item.getColor()]&gt;&gt;<\/code>. The tag will use the exact RGB values of the returned <code>Color<\/code> object.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What happens if the text already has a color applied before the <code>textColor<\/code> tag is evaluated?<br>\n<strong>A:<\/strong> The existing color is preserved; the <code>textColor<\/code> tag only affects text that does <strong>not<\/strong> already have a color defined. This prevents overriding manually set colors.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I nest <code>textColor<\/code> tags or use them inside a <code>foreach<\/code> loop?<br>\n<strong>A:<\/strong> Both are supported. Nested tags allow hierarchical coloring, and using <code>textColor<\/code> inside <code>foreach<\/code> lets you apply a different color for each iteration based on the data source.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> I receive a \u201cTag end is unexpected\u201d error when using <code>textColor<\/code>. What could be wrong?<br>\n<strong>A:<\/strong> The error usually indicates a mismatched opening\/closing tag or an invalid expression. Ensure the opening tag is <code>&lt;&lt;textColor [expression]&gt;&gt;<\/code> and the closing tag is exactly <code>&lt;&lt;\/textColor&gt;&gt;<\/code>, with no extra characters or missing brackets.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Setting Background Color Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/setting-background-color-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/setting-background-color-dynamically\/","description":"\n        \n        \n        <p>You can set text background color for document contents dynamically using <code>backColor<\/code> tags. Syntax of a <code>backColor<\/code> tag is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">backColor<\/span> <span class=\"p\">[<\/span><span class=\"n\">color_expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<span class=\"n\">content_to_be_colored<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">backColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 A <code>backColor<\/code> tag can be used anywhere in a template document except charts.<\/p>\n<p>An expression declared within an opening <code>backColor<\/code> tag defines a text background color to be applied during runtime. The expression must return a value of one of the following types:<\/p>\n<ul>\n<li>A string containing the name of a known color, that is, the case-insensitive name of a member of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.drawing.knowncolor?view=net-6.0\">KnownColor<\/a> enumeration like in the following example.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">backColor<\/span> <span class=\"p\">[<\/span><span class=\"err\">\u201c<\/span><span class=\"n\">red<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">with<\/span> <span class=\"n\">red<\/span> <span class=\"n\">background<\/span><span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">backColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>A string containing an HTML color code like in the following example.<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">backColor<\/span> <span class=\"p\">[<\/span><span class=\"err\">\u201c#<\/span><span class=\"n\">F08080<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">with<\/span> <span class=\"n\">light<\/span> <span class=\"n\">coral<\/span> <span class=\"n\">background<\/span><span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">backColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>An integer value defining RGB (red, green, blue) components of the color like in the following example.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">backColor<\/span> <span class=\"p\">[<\/span><span class=\"m\">0<\/span><span class=\"n\">xFFFF00<\/span><span class=\"p\">]&gt;&gt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">with<\/span> <span class=\"n\">yellow<\/span> <span class=\"n\">background<\/span><span class=\"p\">&lt;&lt;\/<\/span><span class=\"n\">backColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>A value of the <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/awt\/Color.html\">Color<\/a> type.<\/li>\n<\/ul>\n<p>While building a report, an expression declared within an opening <code>backColor<\/code> tag is evaluated and document content between the tag and its corresponding closing tag is colored accordingly. The opening and closing <code>backColor<\/code> tags are removed then.<\/p>\n<p><strong>Note<\/strong> \u2013 Within a document block to be colored using a <code>backColor<\/code> tag, elements having a text background color already applied are not affected during runtime.<\/p>\n<p>You can use <code>backColor<\/code> tags nested into each other. Also, you can normally use <code>backColor<\/code> tags within data bands and conditional blocks like in the following example.<\/p>\n<p>Assume that you have the <code>ColoredItem<\/code> class defined in your application as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">ColoredItem<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getName<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getDescription<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">Color<\/span> <span class=\"n\">getColor<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"p\">...<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre><\/div>\n<p>Given that <code>items<\/code> is an enumeration of <code>ColoredItem<\/code> instances, you can use the following template to output every item into a separate paragraph colored dynamically.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">item<\/span> <span class=\"k\">in<\/span> <span class=\"n\">items<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;<\/span><span class=\"n\">backColor<\/span> <span class=\"p\">[<\/span><span class=\"n\">item<\/span><span class=\"p\">.<\/span><span class=\"n\">getColor<\/span><span class=\"p\">()]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">item<\/span><span class=\"p\">.<\/span><span class=\"n\">getName<\/span><span class=\"p\">()]&gt;&gt;&lt;&lt;\/<\/span><span class=\"n\">backColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>To output every item into a separate table row colored dynamically, you can use the following template.<\/p>\n<table class=\"setting-background-color-dynamically\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>&lt;&lt;foreach [item in items]>>&lt;&lt;backColor [item.getColor()]>>&lt;&lt;[item.getName()]>><\/td>\n\t\t\t<td>&lt;&lt;[item.getDescription()]>>&lt;&lt;\/backColor>>&lt;&lt;\/foreach>><\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p><strong>Note<\/strong> \u2013 Start and end <code>backColor<\/code> tags can be located either in paragraphs of a single story (or table cell) or in rows of a single document table in the same way as <code>foreach<\/code> tags.<\/p>\n<p>Also, you can use a <code>backColor<\/code> tag to set a solid-fill color for a shape dynamically by performing the following steps:<\/p>\n<ol>\n<li>Add a required shape to your template.<\/li>\n<li>Set the shape\u2019s fill to none (that is, \u201cNo fill\u201d).<\/li>\n<li>Inside the shape\u2019s textbox, add opening and closing <code>backColor<\/code> tags so that they to enclose the whole text inside the textbox, if any, like in the following example.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">backColor<\/span> <span class=\"p\">[<\/span><span class=\"err\">\u201c<\/span><span class=\"n\">red<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;<\/span><span class=\"n\">text<\/span> <span class=\"n\">inside<\/span> <span class=\"n\">shape<\/span><span class=\"p\">&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;\/<\/span><span class=\"n\">backColor<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/li>\n<\/ol>\n<p>During runtime, an expression declared within the opening <code>backColor<\/code> tag is evaluated and the shape\u2019s solid\u2011fill color is set accordingly. The opening and closing <code>backColor<\/code> tags are removed then.<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> What types of values can I use in a <code>backColor<\/code> tag expression?<br>\n<strong>A:<\/strong> The expression may return a string with a known color name (e.g., \u201cred\u201d), a string with an HTML hex code (e.g., \u201c#F08080\u201d), an integer representing an RGB value (e.g., <code>0xFFFF00<\/code>), or a <code>java.awt.Color<\/code> object.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can <code>backColor<\/code> tags be nested inside each other?<br>\n<strong>A:<\/strong> Yes. Nested <code>backColor<\/code> tags are supported; the innermost tag overrides the outer one for the enclosed text, and all tags are stripped after processing.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I apply a dynamic background color to a shape\u2019s text?<br>\n<strong>A:<\/strong> Insert a shape with \u201cNo fill\u201d, place opening and closing <code>backColor<\/code> tags inside the shape\u2019s textbox around the text, and use an expression that returns a supported color value. At runtime the shape\u2019s solid\u2011fill color will be set to the evaluated color.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Are <code>backColor<\/code> tags usable inside tables or data\u2011band blocks such as <code>foreach<\/code>?<br>\n<strong>A:<\/strong> Absolutely. <code>backColor<\/code> tags work the same way inside table cells, rows, or any data band. They may span across cells as long as they remain within the same story.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What happens to text that already has a background color when a <code>backColor<\/code> tag is applied?<br>\n<strong>A:<\/strong> Existing background colors are left unchanged; the <code>backColor<\/code> tag only affects text that does not already have a background color applied.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Merging Table Cells Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/merging-table-cells-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/merging-table-cells-dynamically\/","description":"\n        \n        \n        <p>You can merge table cells with equal textual contents within your reports dynamically using <code>cellMerge<\/code> tags. Syntax of a <code>cellMerge<\/code> tag is defined as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">cellMerge<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>By default, a <code>cellMerge<\/code> tag causes a cell merging operation only in a vertical direction during runtime. However, you can alter this behavior in the following ways:<\/p>\n<ul>\n<li>\n<p>To merge cells only in a horizontal direction, use the <code>horz<\/code> switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">cellMerge<\/span> <span class=\"p\">-<\/span><span class=\"n\">horz<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/p>\n<\/li>\n<li>\n<p>To merge cells in both \u2013 vertical and horizontal \u2013 directions, use the both switch as follows.\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">cellMerge<\/span> <span class=\"p\">-<\/span><span class=\"n\">both<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div><\/p>\n<\/li>\n<\/ul>\n<p>For two or more successive table cells to be merged dynamically in either direction by the engine, the following requirements must be met:<\/p>\n<ul>\n<li>Each of the cells must contain a <code>cellMerge<\/code> tag denoting a cell merging operation in the same direction.<\/li>\n<li>Each of the cells must not be already merged in another direction. This requirement does not apply when a <code>both<\/code> switch is used.<\/li>\n<li>The cells must have equal textual contents ignoring leading and trailing whitespaces.<\/li>\n<\/ul>\n<p>Consider the following template.<\/p>\n<table class=\"outputting-sequential-data\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>&lt;&lt;cellMerge>>&lt;&lt;[value1]>><\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n    <tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>&lt;&lt;cellMerge>>&lt;&lt;[value2]>><\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n    <tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p>If <code>value1<\/code> and <code>value2<\/code> have the same value, say \u201cHello\u201d, table cells containing <code>cellMerge<\/code> tags are successfully merged during runtime and a result report looks as follows then.<\/p>\n<table class=\"outputting-sequential-data\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>...<\/td>\n      <td rowspan=\"2\" style=\"vertical-align: middle\"><strong>Hello<\/strong><\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n    <tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n    <tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p>If <code>value1<\/code> and <code>value2<\/code> have different values, say \u201cHello\u201d and \u201cWorld\u201d, table cells containing <code>cellMerge<\/code> tags are not merged during runtime and a result report looks as follows then.<\/p>\n<table class=\"outputting-sequential-data\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>...<\/td>\n      <td style=\"vertical-align: middle\"><strong>Hello<\/strong><\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n    <tr>\n\t\t\t<td>...<\/td>\n      <td style=\"vertical-align: middle\"><strong>World<\/strong><\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n    <tr>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t\t<td>...<\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p><strong>Note<\/strong> \u2013 A <code>cellMerge<\/code> tag can be normally used within a table data band.<\/p>\n<p>You can define an additional restriction on dynamic merging of table cells by providing an expression for a <code>cellMerge<\/code> tag using the following syntax.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"n\">cellMerge<\/span> <span class=\"p\">[<\/span><span class=\"n\">expression<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>During runtime, expressions defined for <code>cellMerge<\/code> tags are evaluated and dynamic cell merging is discarded for those tags, which expressions return unequal values, even if all other conditions for merging such as equal cell textual contents are met. In particular, this feature is useful when cells corresponding to different data band sequence elements should not be merged as shown in the following example.<\/p>\n<p>Assume that you have the <code>Invoice<\/code> and <code>InvoiceItem<\/code> classes defined in your application as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">Invoice<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"kt\">int<\/span> <span class=\"n\">getNumber<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">Iterable<\/span><span class=\"p\">&lt;<\/span><span class=\"n\">InvoiceItem<\/span><span class=\"p\">&gt;<\/span> <span class=\"n\">getItems<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"p\">...<\/span>\n<span class=\"p\">}<\/span>\n<span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">InvoiceItem<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getWare<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getPack<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"kt\">int<\/span> <span class=\"n\">getQuantity<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"p\">...<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre><\/div>\n<p>Given that <code>invoices<\/code> is an enumeration of Invoice instances, you could use the following template to output information on several invoices in one table.<\/p>\n<table class=\"outputting-sequential-data\">\n\t<tbody>\n\t\t<tr>\n      <td><strong>#<\/strong><\/td>\n\t\t\t<td><strong>Ware<\/strong><\/td>\n      <td><strong>Pack<\/strong><\/td>\n      <td><strong>Quantity<\/strong><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>&lt;&lt;foreach [invoice in invoices]>>&lt;&lt;foreach [item in invoice.getItems()]>>&lt;&lt;[invoice.getNumber()]>>&lt;&lt;cellMerge>><\/td>\n      <td>&lt;&lt;[item.getWare()]>>&lt;&lt;cellMerge>><\/td>\n      <td>&lt;&lt;[item.getPack()]>><\/td>\n      <td>&lt;&lt;[item.getQuantity()]>>&lt;&lt;\/foreach>>&lt;&lt;\/foreach>><\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p>A result document would look as follows then.<\/p>\n<table>\n\t<tbody>\n\t\t<tr>\n\t\t\t<td><b>#<\/b><\/td>\n\t\t\t<td><b>Ware<\/b><\/td>\n\t\t\t<td><b>Pack<\/b><\/td>\n\t\t\t<td><b>Quantity<\/b><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td rowspan=\"2\">11342<\/td>\n\t\t\t<td rowspan=\"3\">Natural Mineral Water<\/td>\n\t\t\t<td>Bottle 1.0 L<\/td>\n\t\t\t<td>30<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>Bottle 0.5 L<\/td>\n\t\t\t<td>50<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>15385<\/td>\n\t\t\t<td>Bottle 1.0 L<\/td>\n\t\t\t<td>110<\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p>That is, cells corresponding to the same wares at different invoices would be merged, which is unwanted. To prevent this from happening, you can use the following template instead.<\/p>\n<table class=\"outputting-sequential-data\">\n\t<tbody>\n\t\t<tr>\n      <td><strong>#<\/strong><\/td>\n\t\t\t<td><strong>Ware<\/strong><\/td>\n      <td><strong>Pack<\/strong><\/td>\n      <td><strong>Quantity<\/strong><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>&lt;&lt;foreach [invoice in invoices]>>&lt;&lt;foreach [item in invoice.getItems()]>>&lt;&lt;[invoice.getNumber()]>>&lt;&lt;cellMerge>><\/td>\n      <td>&lt;&lt;[item.getWare()]>>&lt;&lt;cellMerge [invoice.indexOf()]>><\/td>\n      <td>&lt;&lt;[item.getPack()]>><\/td>\n      <td>&lt;&lt;[item.getQuantity()]>>&lt;&lt;\/foreach>>&lt;&lt;\/foreach>><\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p>Then, a result document looks as follows.<\/p>\n<table>\n\t<tbody>\n\t\t<tr>\n\t\t\t<td><b>#<\/b><\/td>\n\t\t\t<td><b>Ware<\/b><\/td>\n\t\t\t<td><b>Pack<\/b><\/td>\n\t\t\t<td><b>Quantity<\/b><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td rowspan=\"2\">11342<\/td>\n\t\t\t<td rowspan=\"2\">Natural Mineral Water<\/td>\n\t\t\t<td>Bottle 1.0 L<\/td>\n\t\t\t<td>30<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>Bottle 0.5 L<\/td>\n\t\t\t<td>50<\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>15385<\/td>\n      <td>Natural Mineral Water<\/td>\n\t\t\t<td>Bottle 1.0 L<\/td>\n\t\t\t<td>110<\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p><strong>Note<\/strong> \u2013 You could use <code>&lt;&lt;cellMerge [invoice.getNumber()]&gt;&gt;<\/code> instead of <code>&lt;&lt;cellMerge [invoice.indexOf()]&gt;&gt;<\/code> to get the same effect, but using of <code>indexOf()<\/code> is a more generic approach.<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I merge cells only horizontally with a <code>cellMerge<\/code> tag?<br>\n<strong>A:<\/strong> Add the <code>-horz<\/code> switch to the tag: <code>&lt;&lt;cellMerge -horz&gt;&gt;<\/code>. This tells the engine to merge successive cells in the same row when their textual contents match.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can a single <code>cellMerge<\/code> tag merge cells both vertically and horizontally?<br>\n<strong>A:<\/strong> Yes. Use the <code>-both<\/code> switch: <code>&lt;&lt;cellMerge -both&gt;&gt;<\/code>. The engine will attempt to merge cells in both directions, provided all merging requirements are satisfied.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What conditions must be met for cells to merge dynamically?<br>\n<strong>A:<\/strong> (a) Each cell must contain a <code>cellMerge<\/code> tag with the same direction switch. (b) Cells must not already be part of another merge in a conflicting direction (unless <code>-both<\/code> is used). (c) The textual content of the cells must be identical after trimming leading\/trailing whitespace.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I prevent cells from merging across different data items, such as different invoices?<br>\n<strong>A:<\/strong> Supply an expression to the <code>cellMerge<\/code> tag that evaluates differently for each data group, e.g., <code>&lt;&lt;cellMerge [invoice.indexOf()]&gt;&gt;<\/code>. The engine will only merge cells when the expression returns equal values.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it safe to use <code>cellMerge<\/code> tags inside a table data band?<br>\n<strong>A:<\/strong> Yes. <code>cellMerge<\/code> tags are designed to work inside table data bands and will be processed during the rendering of each band iteration.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Restarting List Numbering Dynamically in Java","link":"https:\/\/docs.aspose.com\/words\/java\/restarting-list-numbering-dynamically\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/restarting-list-numbering-dynamically\/","description":"\n        \n        \n        <p>You can restart list numbering within your documents dynamically using <code>restartNum<\/code> tags. In particular, this feature is useful when working with a nested numbered list within a data band as shown in the following example.<\/p>\n<p>Assume that you have the <code>Order<\/code> and <code>Service<\/code> classes defined in your application as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">Order<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getClientName<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getClientAddress<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">Iterable<\/span><span class=\"p\">&amp;<\/span><span class=\"n\">lt<\/span><span class=\"p\">;<\/span><span class=\"n\">Service<\/span><span class=\"p\">&amp;<\/span><span class=\"n\">gt<\/span><span class=\"p\">;<\/span> <span class=\"n\">getServices<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"p\">...<\/span>\n<span class=\"p\">}<\/span>\n\n<span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">Service<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"n\">String<\/span> <span class=\"n\">getName<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span> <span class=\"p\">...<\/span> <span class=\"p\">}<\/span>\n\t<span class=\"p\">...<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre><\/div>\n<p>Given that <code>orders<\/code> is an enumeration of <code>Order<\/code> instances, you could try to use the following template to output information on several orders in one document.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">order<\/span> <span class=\"k\">in<\/span> <span class=\"n\">orders<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">order<\/span><span class=\"p\">.<\/span><span class=\"n\">getClientName<\/span><span class=\"p\">()]&gt;&gt;<\/span> <span class=\"p\">(&lt;&lt;[<\/span><span class=\"n\">order<\/span><span class=\"p\">.<\/span><span class=\"n\">getClientAddress<\/span><span class=\"p\">()]&gt;&gt;)<\/span>\n\t<span class=\"m\">1.<\/span> <span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">service<\/span> <span class=\"k\">in<\/span> <span class=\"n\">order<\/span><span class=\"p\">.<\/span><span class=\"n\">getServices<\/span><span class=\"p\">()]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">service<\/span><span class=\"p\">.<\/span><span class=\"n\">getName<\/span><span class=\"p\">()]&gt;&gt;<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>But then, a result document would look as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">Jane<\/span> <span class=\"n\">Doe<\/span> <span class=\"p\">(<\/span><span class=\"m\">445<\/span> <span class=\"n\">Mount<\/span> <span class=\"n\">Eden<\/span> <span class=\"n\">Road<\/span> <span class=\"n\">Mount<\/span> <span class=\"n\">Eden<\/span> <span class=\"n\">Auckland<\/span> <span class=\"m\">1024<\/span><span class=\"p\">)<\/span>\n\n<span class=\"m\">1.<\/span> <span class=\"n\">Regular<\/span> <span class=\"n\">Cleaning<\/span>\n<span class=\"m\">2.<\/span> <span class=\"n\">Oven<\/span> <span class=\"n\">Cleaning<\/span>\n\n<span class=\"n\">John<\/span> <span class=\"n\">Smith<\/span> <span class=\"p\">(<\/span><span class=\"m\">43<\/span> <span class=\"n\">Vogel<\/span> <span class=\"n\">Street<\/span> <span class=\"n\">Roslyn<\/span> <span class=\"n\">Palmerston<\/span> <span class=\"n\">North<\/span> <span class=\"m\">4414<\/span><span class=\"p\">)<\/span>\n\n<span class=\"m\">3.<\/span> <span class=\"n\">Regular<\/span> <span class=\"n\">Cleaning<\/span>\n<span class=\"m\">4.<\/span> <span class=\"n\">Oven<\/span> <span class=\"n\">Cleaning<\/span>\n<span class=\"m\">5.<\/span> <span class=\"n\">Carpet<\/span> <span class=\"n\">Cleaning<\/span>\n<\/code><\/pre><\/div>\n<p>That is, there would be a single numbered list across all orders, which is not applicable for this scenario. However, you can make list numbering to restart for every order by putting a <code>restartNum<\/code> tag into your template before a corresponding <code>foreach<\/code> tag as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">order<\/span> <span class=\"k\">in<\/span> <span class=\"n\">orders<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">order<\/span><span class=\"p\">.<\/span><span class=\"n\">getClientName<\/span><span class=\"p\">()]&gt;&gt;<\/span> <span class=\"p\">(&lt;&lt;[<\/span><span class=\"n\">order<\/span><span class=\"p\">.<\/span><span class=\"n\">getClientAddress<\/span><span class=\"p\">()]&gt;&gt;)<\/span>\n\t<span class=\"m\">1.<\/span> <span class=\"p\">&lt;&lt;<\/span><span class=\"n\">restartNum<\/span><span class=\"p\">&gt;&gt;&lt;&lt;<\/span><span class=\"k\">foreach<\/span> <span class=\"p\">[<\/span><span class=\"n\">service<\/span> <span class=\"k\">in<\/span> <span class=\"n\">order<\/span><span class=\"p\">.<\/span><span class=\"n\">getServices<\/span><span class=\"p\">()]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">service<\/span><span class=\"p\">.<\/span><span class=\"n\">getName<\/span><span class=\"p\">()]&gt;&gt;<\/span>\n<span class=\"p\">&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;&lt;&lt;\/<\/span><span class=\"k\">foreach<\/span><span class=\"p\">&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 When using with a data band, it is required to put a <code>restartNum<\/code> tag before a corresponding <code>foreach<\/code> tag in the same numbered paragraph.<\/p>\n<p>Then, a result document looks as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">Jane<\/span> <span class=\"n\">Doe<\/span> <span class=\"p\">(<\/span><span class=\"m\">445<\/span> <span class=\"n\">Mount<\/span> <span class=\"n\">Eden<\/span> <span class=\"n\">Road<\/span> <span class=\"n\">Mount<\/span> <span class=\"n\">Eden<\/span> <span class=\"n\">Auckland<\/span> <span class=\"m\">1024<\/span><span class=\"p\">)<\/span>\n\n<span class=\"m\">1.<\/span> <span class=\"n\">Regular<\/span> <span class=\"n\">Cleaning<\/span>\n<span class=\"m\">2.<\/span> <span class=\"n\">Oven<\/span> <span class=\"n\">Cleaning<\/span>\n\n<span class=\"n\">John<\/span> <span class=\"n\">Smith<\/span> <span class=\"p\">(<\/span><span class=\"m\">43<\/span> <span class=\"n\">Vogel<\/span> <span class=\"n\">Street<\/span> <span class=\"n\">Roslyn<\/span> <span class=\"n\">Palmerston<\/span> <span class=\"n\">North<\/span> <span class=\"m\">4414<\/span><span class=\"p\">)<\/span>\n\n<span class=\"m\">3.<\/span> <span class=\"n\">Regular<\/span> <span class=\"n\">Cleaning<\/span>\n<span class=\"m\">4.<\/span> <span class=\"n\">Oven<\/span> <span class=\"n\">Cleaning<\/span>\n<span class=\"m\">5.<\/span> <span class=\"n\">Carpet<\/span> <span class=\"n\">Cleaning<\/span>\n<\/code><\/pre><\/div>\n<p><strong>Note<\/strong> \u2013 You can use a <code>restartNum<\/code> tag without a data band to dynamically restart list numbering for a containing paragraph, if needed; for example, the tag can be used to restart list numbering for a document inserted dynamically (see \u201cInserting Documents Dynamically\u201d for more information).<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I restart list numbering for each iteration of a <code>foreach<\/code> loop?<br>\n<strong>A:<\/strong> Place the <code>&lt;&lt;restartNum&gt;&gt;<\/code> tag immediately before the <code>&lt;&lt;foreach&gt;&gt;<\/code> tag that generates the list items. The tag must be inside the same numbered paragraph where the list starts, ensuring the numbering restarts for each new iteration.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can the <code>restartNum<\/code> tag be used when there is no data band (no <code>foreach<\/code>)?<br>\n<strong>A:<\/strong> Yes. <code>restartNum<\/code> works independently of data bands; you can insert it before any numbered paragraph to reset the numbering at that point, such as when inserting a document fragment that contains its own list.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Does <code>restartNum<\/code> affect nested lists or only the top\u2011level list?<br>\n<strong>A:<\/strong> <code>restartNum<\/code> resets the numbering of the list that contains the tag. If you have nested lists, only the outer list numbering is restarted. Nested lists will continue their own numbering unless you also place a <code>restartNum<\/code> tag within the nested list\u2019s paragraph.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Where should the <code>restartNum<\/code> tag be placed relative to the <code>foreach<\/code> tag?<br>\n<strong>A:<\/strong> The tag must appear <strong>before<\/strong> the <code>&lt;&lt;foreach&gt;&gt;<\/code> tag inside the same paragraph that contains the list number (e.g., <code>1.<\/code>). This ensures the list numbering is reset before the loop generates its items.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is the <code>restartNum<\/code> tag supported in Aspose.Words for Java?<br>\n<strong>A:<\/strong> Yes. The <code>restartNum<\/code> tag is part of the Aspose.Words templating engine and works the same way in Java as in other .NET languages. Use it in your Java templates exactly as shown in the examples.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Using Contextual Object Member Access in Java","link":"https:\/\/docs.aspose.com\/words\/java\/using-contextual-object-member-access\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/using-contextual-object-member-access\/","description":"\n        \n        \n        <p>You can make your templates less cumbersome using the contextual object member access feature. This feature enables you to access members of some objects without specifying the objects' identifiers in template expressions. An object to which the feature can be applied is determined depending on a\ncontext as follows:<\/p>\n<ul>\n<li>Inside a data band body, the object is resolved to the innermost iteration variable.<\/li>\n<li>Outside a data band body, the object is resolved to a passed data source.<\/li>\n<\/ul>\n<p>Obviously, inside a data band body, you can not use the feature to access members of an outer iteration variable or a passed data source object. With the exception of this restriction, you can use both contextual and common object member access syntaxes interchangeably depending on your needs and preferences.<\/p>\n<p>Consider the following example. Given that <code>ds<\/code> is a <code>DataSet<\/code> instance containing a <code>DataTable<\/code> object named \u201cPersons\u201d that has fields named \u201cName\u201d and \u201cAge\u201d, you can use the following template to list the contents of the table.<\/p>\n<table class=\"ct\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td><strong>No.<\/strong><\/td>\n\t\t\t<td><strong>Name<\/strong><\/td>\n\t\t\t<td><strong>Age<\/strong><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>&lt;&lt;foreach [p \n    in ds.Persons]>>&lt;&lt;[\n  p.numberOf()]>><\/td>\n\t\t\t<td>&lt;&lt;[p.Name]>><\/td>\n\t\t\t<td>&lt;&lt;[p.Age]>>&lt;&lt;\/foreach>><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td colspan=\"3\">Count: &lt;&lt;[ds.Persons.count()]>><\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<p>Alternatively, you can use the following template involving the contextual object member access syntax to get the same results.<\/p>\n<table class=\"iksweb\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td><strong>No.<\/strong><\/td>\n\t\t\t<td><strong>Name<\/strong><\/td>\n\t\t\t<td><strong>Age<\/strong><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td>&lt;&lt;foreach [\n    in Persons]>>&lt;&lt;[\n  numberOf()]>><\/td>\n\t\t\t<td>&lt;&lt;[Name]>><\/td>\n\t\t\t<td>&lt;&lt;[Age]>>&lt;&lt;\/foreach>><\/td>\n\t\t<\/tr>\n\t\t<tr>\n\t\t\t<td colspan=\"3\">Count: &lt;&lt;[Persons.count()]>><\/td>\n\t\t<\/tr>\n\t<\/tbody>\n<\/table>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How does contextual object member access differ from regular member access in template expressions?<br>\n<strong>A:<\/strong> Contextual access lets you omit the object identifier; the engine automatically resolves the member to the innermost iteration variable (inside a data band) or to the passed data source (outside a data band). Regular access requires you to specify the full path, such as <code>ds.Persons.Name<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I use contextual object member access to reference an outer iteration variable from within a nested loop?<br>\n<strong>A:<\/strong> No. Inside a data band, contextual access always resolves to the innermost iteration variable. To reach an outer variable you must use the regular object member syntax with the appropriate identifier.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I count the number of items in a data source using contextual syntax?<br>\n<strong>A:<\/strong> Use the <code>count()<\/code> method on the collection name without a prefix, e.g., <code>&lt;&lt;[Persons.count()]&gt;&gt;<\/code> when the template is outside a data band, or <code>&lt;&lt;[count()]&gt;&gt;<\/code> inside a <code>foreach<\/code> that iterates over <code>Persons<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What happens if I try to use contextual member access outside a data band body?<br>\n<strong>A:<\/strong> The engine resolves the member to the passed data source object. If no data source is supplied, the expression will fail with a \u201cmember not found\u201d error. In such cases, specify the full data source identifier.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to mix contextual and regular member access in the same template?<br>\n<strong>A:<\/strong> Yes. You can use contextual syntax where it is allowed and fall back to regular syntax for cases that require explicit object references, such as accessing outer loop variables or when you need clarity in complex templates.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Using Variables in Java","link":"https:\/\/docs.aspose.com\/words\/java\/using-variables\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/using-variables\/","description":"\n        \n        \n        <p>LINQ Reporting Engine enables you to use variables in template documents. Variables are useful when you need to calculate an expensive value just once and access it multiple times in a template. Also, calculation of complex values such as running (progressive) totals may require variables, see \u201cAppendix C. Typical Templates\u201d to get an example.<\/p>\n<p>You can declare a variable in a template using a var tag as follows.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"kt\">var<\/span> <span class=\"p\">[<\/span><span class=\"n\">variable_type<\/span> <span class=\"n\">variable_name<\/span> <span class=\"p\">=<\/span> <span class=\"n\">variable_value<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>The following table describes elements of the var tag.<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">Element<\/th>\n<th style=\"text-align:left\">Optional?<\/th>\n<th style=\"text-align:left\">Remarks<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\"><strong>Variable Type<\/strong><\/td>\n<td style=\"text-align:left\">Yes<\/td>\n<td style=\"text-align:left\">You can specify the type of a variable explicitly. This type must be known by the engine (see \u201cSetting up Known External Types\u201d for more information).<br \/>If you do not specify the type explicitly, it is determined implicitly by the engine from the specified variable value.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Variable Name<\/strong><\/td>\n<td style=\"text-align:left\">No<\/td>\n<td style=\"text-align:left\">For a new variable, its name must be a unique identifier.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Assignment Operator<\/strong><\/td>\n<td style=\"text-align:left\">No<\/td>\n<td style=\"text-align:left\"><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Variable Value<\/strong><\/td>\n<td style=\"text-align:left\">No<\/td>\n<td style=\"text-align:left\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>During runtime, a <code>var<\/code> tag is removed while the value of the corresponding variable is calculated and set appropriately.<\/p>\n<p>After a variable is declared in a template, its value can be accessed using the name of the variable as any other identifier. For example, the following template outputs string \u201cHello!\u201d<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"kt\">var<\/span> <span class=\"p\">[<\/span><span class=\"n\">s<\/span> <span class=\"p\">=<\/span> <span class=\"err\">\u201c<\/span><span class=\"n\">Hello<\/span><span class=\"p\">!<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">s<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>You can redefine the value of a variable using a <code>var<\/code> tag against the name of this variable. For example, the following template outputs string \u201cHello, World!\u201d<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">&lt;&lt;<\/span><span class=\"kt\">var<\/span> <span class=\"p\">[<\/span><span class=\"n\">s<\/span> <span class=\"p\">=<\/span> <span class=\"err\">\u201c<\/span><span class=\"n\">Hello<\/span><span class=\"p\">,<\/span> <span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">s<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;<\/span><span class=\"kt\">var<\/span> <span class=\"p\">[<\/span><span class=\"n\">s<\/span> <span class=\"p\">=<\/span> <span class=\"err\">\u201c<\/span><span class=\"n\">World<\/span><span class=\"p\">!<\/span><span class=\"err\">\u201d<\/span><span class=\"p\">]&gt;&gt;&lt;&lt;[<\/span><span class=\"n\">s<\/span><span class=\"p\">]&gt;&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>Using of variables has the following restrictions:<\/p>\n<ul>\n<li>You can not redefine the type of a variable.<\/li>\n<li>You can not use the contextual object member access feature against a variable. See \u201cUsing Contextual Object Member Access\u201d for more information.<\/li>\n<li>Using a <code>var<\/code> tag, you can not redefine the value of an iteration variable or a data source.<\/li>\n<\/ul>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I declare a variable with an explicit type in a template?<br>\n<strong>A:<\/strong> Include the type before the variable name inside the <code>var<\/code> tag, e.g. <code>&lt;&lt;var [java.time.LocalDate startDate = DateTime.Now]&gt;<\/code>. The engine must know the type; you can register custom types via \u201cSetting up Known External Types\u201d.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I reference a variable after it has been declared?<br>\n<strong>A:<\/strong> Use the variable name inside double\u2011angle brackets. For example, after <code>&lt;&lt;var [total = 0]&gt;<\/code>, you can output its value with <code>&lt;&lt;[total]&gt;&gt;<\/code> anywhere later in the document.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I change the type of a variable once it has been created?<br>\n<strong>A:<\/strong> No. The variable\u2019s type is fixed at the first declaration and cannot be redefined. Attempting to declare the same name with a different type will cause a runtime error.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to redefine a variable\u2019s value inside a <code>foreach<\/code> loop?<br>\n<strong>A:<\/strong> Yes, you may assign a new value to the same variable inside a loop using another <code>var<\/code> tag, e.g. <code>&lt;&lt;var [sum = sum + item.Price]&gt;&gt;<\/code>. However, you cannot change the variable\u2019s type or redefine an iteration variable itself.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I use a variable to format a date inside a template?<br>\n<strong>A:<\/strong> Declare a variable that holds the formatted string, for example: <code>&lt;&lt;var [java.time.format.DateTimeFormatter fmt = java.time.format.DateTimeFormatter.ofPattern(&quot;yyyy-MM-dd&quot;)]&gt;&gt;<\/code> then <code>&lt;&lt;var [formattedDate = dateValue.format(fmt)]&gt;&gt;<\/code>. Output with <code>&lt;&lt;[formattedDate]&gt;&gt;<\/code>. This avoids repeated formatting calls.<\/p>\n<\/li>\n<\/ol>\n\n      "}]}}