Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
ArrayAsSingle attribute along with the ExtraDelimiter attribute, developers can control how array elements are separated within a single cell, providing flexible formatting for reports and templates.
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.
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.
There are many practical scenarios where the default spreading behavior is undesirable:
Without a built-in mechanism, developers would be forced to pre-process data in Python — 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.
Using the ArrayAsSingle and ExtraDelimiter attributes in your Smart Markers provides several advantages:
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.extraDelimiter attribute accepts any string literal, including multi-character delimiters, custom text, or escape sequences such as \n for newline-separated output. If the array is empty, the resulting cell is left blank.
The following workflow describes how to render an array into a single cell using Smart Markers.
string[], int[], or any other supported array type.Workbook, add a header row, and place a Smart Marker cell that references the array property with the arrayasSingle and extraDelimiter attributes.WorkbookDesigner object, attach the designer workbook to it, and bind your data source using the set_data_source method.WorkbookDesigner.process() method to expand the Smart Markers and populate the workbook with real data.import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
from asposecells.api import Workbook, WorkbookDesigner
class Product:
def __init__(self, tags):
self._tags = tags
def getTags(self):
return self._tags
product = Product(["C#", "Aspose", "SmartMarker", "Excel"])
workbook = Workbook()
worksheet = workbook.getWorksheets().get(0)
worksheet.getCells().get("A1").putValue("Tags")
worksheet.getCells().get("A2").putValue("&=Product.Tags(arrayasSingle=true, extraDelimiter=\", \")")
designer = WorkbookDesigner()
designer.setWorkbook(workbook)
designer.setDataSource("Product", product)
designer.process()
workbook.save("output_arraySingle.xlsx")
jpype.shutdownJVM()
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
from asposecells.api import Workbook
# Define Student class
class Student:
def __init__(self):
self.Scores = []
student = Student()
student.Scores = [95, 88, 76, 100, 67]
workbook = Workbook()
worksheet = workbook.getWorksheets().get(0)
worksheet.getCells().get("A1").putValue("Scores")
worksheet.getCells().get("A2").putValue(" - ".join(str(s) for s in student.Scores))
workbook.save("output_numericArray.xlsx")
jpype.shutdownJVM()
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
from asposecells.api import Workbook, WorkbookDesigner
# Define the data source as a dictionary (equivalent to the Order class)
order = {"Items": ["Apple", "Banana", "Cherry", "Date"]}
workbook = Workbook()
sheet = workbook.getWorksheets().get(0)
cells = sheet.getCells()
# Section 1: Default Smart Marker - values spread horizontally across cells
cells.get("A1").putValue("Default Spreading Behavior:")
cells.get("A2").putValue("&=Order.Items")
# Section 2: New single-cell rendering using arrayasSingle and extraDelimiter
cells.get("A4").putValue("Single Cell Rendering (arrayasSingle=true):")
cells.get("A5").putValue("&=Order.Items(arrayasSingle=true, extraDelimiter=\"; \")")
# Bind the data source and process Smart Markers
designer = WorkbookDesigner(workbook)
designer.setDataSource("Order", order)
designer.process()
# Save the resulting workbook
workbook.save("output_comparison.xlsx")
jpype.shutdownJVM()
Keep the following points in mind when working with the ArrayAsSingle and ExtraDelimiter attributes:
extraDelimiter value is treated as a string literal; escape any special characters that your template processor might interpret.arrayasSingle attribute accepts a boolean value (true / false). Only true triggers the single-cell behavior; any other value falls back to the default spreading behavior.DataSet and DataTable sources where a column can be split into arrays.\n or the platform’s newline constant as the delimiter value.Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.