SmartMarker Single Cell Array Rendering | Aspose.Cells .NET

Introduction

Smart Markers in Aspose.Cells are a powerful, template-based feature that allows you to dynamically populate spreadsheet data using marker expressions such as &=DataSource.Field. The marker is placed in a designer workbook, and when the template is processed by the WorkbookDesigner, the markers are replaced with values from the supplied data source. By default, when a Smart Marker references an array property (for example, &=DataSource.Numbers), the engine expands the array and places each element into a separate adjacent cell — either horizontally across a row or vertically down a column. While this behavior is convenient in many scenarios, there are situations where you would prefer to render the entire array into one single cell, with the elements concatenated and separated by a delimiter of your choice. The ArrayAsSingle and ExtraDelimiter attributes, used together inside a Smart Marker tag, address exactly this requirement. They allow you to keep report layouts compact and predictable while still working natively with array data sources.

Why This Feature Is Needed

Default Array Spreading Behavior

When a Smart Marker references an array property, Aspose.Cells expands the array across multiple cells by default. For example, a marker such as &=Product.Tags against a string[] containing four values will place each value into its own cell, pushing other template content outward and potentially breaking carefully designed report layouts.

Use Case Limitations

There are many practical scenarios where the default spreading behavior is undesirable:

  • Summary-style reports that need a compact one-row-per-record layout.
  • Tag, label, or keyword lists that need to be displayed as comma-separated or pipe-separated values within a single cell.
  • Filter chips or status indicators that group multiple values in one place for readability.
  • Downstream pipelines (CSV export, PDF rendering, mail merge) that expect a single consolidated value per cell rather than an expanded range.
  • Cross-platform compatibility, where some consumers cannot tolerate arrays that bleed across multiple cells.

The Gap It Fills

Without a built-in mechanism, developers would be forced to pre-process data in C# or VB.NET — joining arrays into delimited strings before binding them to the workbook designer. This duplicates logic, complicates data models, and increases the chance of errors. The ArrayAsSingle and ExtraDelimiter attributes eliminate this workaround by handling the formatting declaratively inside the Smart Marker itself.

Feature Benefits

Using the ArrayAsSingle and ExtraDelimiter attributes in your Smart Markers provides several advantages:

  • Single-cell containment: All array elements are rendered into exactly one cell, keeping layouts compact and predictable.
  • Custom delimiter control: Specify any separator string you like — comma, semicolon, hyphen, pipe, newline, or any custom text.
  • Template-driven formatting: No additional code is required to pre-process the data; formatting rules live inside the Smart Marker tag.
  • Cleaner reports: Array data no longer pushes neighboring template content into different rows or columns.
  • Versatile data types: Works with strings, numbers, dates, and any other data type that can be joined with a delimiter.
  • Backwards compatibility: When the attributes are omitted, the original spreading behavior is preserved, so existing templates continue to work unchanged.

How to Use This Feature

Smart Marker Syntax

The ArrayAsSingle and ExtraDelimiter attributes are passed as key-value pairs inside the parentheses of a standard Smart Marker. The general syntax is:

&=DataSource.ArrayProperty(arrayasSingle=true, extraDelimiter=", ")

The marker is composed of the following parts:

  • &=DataSource.ArrayProperty — the standard Smart Marker referencing the array property on the bound data source.
  • arrayasSingle=true — instructs the engine to render the whole array into a single cell. Only the value true triggers the single-cell behavior.
  • extraDelimiter=", " — defines the separator placed between array elements. The value is a string literal; it can be empty, a single character, or a multi-character string.