Accessing array element by index in Excel template

Hello,

In the Word template, we can access specific array elements using elementAt function.
I wanted to know if we can achieve the same functionality in the Excel template too.

I tried the following smart markers to output the details of the first director from the employees JSON data:
&=RootData.Directors.elementAt(0).id
&=RootData.Directors[0].id

But it did not work for me as expected.

Let me know if accessing array data in JSON input is possible using a smart marker.

Code snippet to allow two cell ranges in the same worksheet:

      designer.setLineByLine(false);
      Cells cells = workbook.getWorksheets().get(0).getCells();
      cells.createRange("A11:H15").setName("_CellsSmartMarkers");
      designer.process(true);

      cells.createRange("A19:H23").setName("_CellsSmartMarkers");
      designer.process(true);

The attached zip file contains:
excel template, input JSON file, and output Excel file.

The output file has 2 worksheets.
The first worksheet has 2 tables for directors. I intend to output details of the first director.
But output has the smart markers instead of the data.

You can see the second worksheet, which outputs all directors’ data.
employees_array_index.zip (27.2 KB)

@sagaofsilence.dev
Sorry, currently cells do not support accessing elements through array indexes in Excel templates. As a temporary solution, you can separate a certain element in the array and then build the data one by one in the template file.

Unfortunately, that option is not feasible. Our service caters to users with diverse needs, which means that users will likely create templates tailored to their specific domains. We have also observed that accessing particular elements of an array is a common requirement. Such elements are accessed as a single data or inside a loop.

@sagaofsilence.dev
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46284

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

@sagaofsilence.dev
I am glad to inform you that we have supported accessing array element by index in Excel template.
CELLSJAVA46284.zip (39.5 KB)

Result files are generated by inner hot fix 25.2.3.

1 Like

Is this available in the maven repo so that I can update the dependency version in my pom file and test it?

@sagaofsilence.dev,

I am afraid, we do not upload fixes to Maven repositories; only official releases are published there. Additionally, fixes are provided exclusively to users with paid support. General users may need to wait for the official releases to come out. Please wait for Aspose.Cells for Java v25.3, which is scheduled for release in the first half of March. You will be notified as soon as the new version becomes available.

Thank you for the update and clarification.

@sagaofsilence.dev
You are welcome. If you have any questions, please feel free to contact us at any time.

The issues you have found earlier (filed as CELLSJAVA-46284) have been fixed in Aspose.Cells for Java 25.3.

@sagaofsilence.dev
Please try the smart marker with [] to export specific data as follows:
&=RootData.Directors[1].reportees.FirstName : Export the second Director
&=RootData.Directors[2:-1].reportees.id : Export the Directors from the third to end