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 Java — 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 setDataSource method.WorkbookDesigner.process() method to expand the Smart Markers and populate the workbook with real data.import com.aspose.cells.*;
class Product {
public String[] Tags;
}
public class CodeRunner {
public static void main(String[] args) throws Exception {
Product product = new Product();
product.Tags = new String[] { "C#", "Aspose", "SmartMarker", "Excel" };
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getCells().get("A1").putValue("Tags");
worksheet.getCells().get("A2").putValue("&=Product.Tags(arrayasSingle=true, extraDelimiter=\", \")");
WorkbookDesigner designer = new WorkbookDesigner();
designer.setWorkbook(workbook);
designer.setDataSource("Product", product);
designer.process();
workbook.save("output_arraySingle.xlsx");
}
}
import com.aspose.cells.*;
class Student
{
public int[] Scores;
}
public class CodeRunner
{
public static void main(String[] args) throws Exception
{
Student student = new Student();
student.Scores = new int[] { 95, 88, 76, 100, 67 };
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getCells().get("A1").putValue("Scores");
StringBuilder joined = new StringBuilder();
for (int i = 0; i < student.Scores.length; i++)
{
if (i > 0) joined.append(" - ");
joined.append(student.Scores[i]);
}
worksheet.getCells().get("A2").putValue(joined.toString());
workbook.save("output_numericArray.xlsx");
}
}
class Order
{
private String[] items;
public String[] getItems()
{
return items;
}
public void setItems(String[] items)
{
this.items = items;
}
}
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 System.lineSeparator() as the delimiter value.Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.