xlsx-template
xlsx-template copied to clipboard
Implement in tables {people: {users: [{name: "John Smith"}]}}
var values = {
people: [
{
name: 'John Smith',
age: 20,
test: { name: 'Smith' },
},
{
name: 'Bob Johnson',
age: 22,
test: { name: 'Johnson' },
},
],
people: {
users: [
{
name: 'John Smith User',
age: 20,
test: { name: 'Smith' },
},
{
name: 'Bob Johnson User',
age: 22,
test: { name: 'Johnson' },
},
],
admins: [
{
name: 'John Smith Admin',
age: 20,
test: { name: 'Smith' },
},
{
name: 'Bob Johnson Admin',
age: 22,
test: { name: 'Johnson' },
},
],
},
};
So for example I have this object values that I want to put into template.
${table:people.name} - this placeholder works ${table:peopleGroup.users.name} - this does not work, in result value is blank
There is no "peopleGroup" field in your values
@romkadj example contains missprint, this is right. However, arrays in nested objects not rendered.
{
rows: [
{name: 'foo'}
],
rowsNested: {
rows: [
{name: 'foo'}
],
}
}
${table:rows.name}
- work
${table:rowsNested.rows.name}
- not work
You can nest objects, not arrays. Nesting an array inside another makes your data structure three dimensional. How do you represent that on a spreadsheet?
Why don't you flatten all your arrays before you pass it to the generator?
@pwarelis I'm not familiar with this lib yet but yes - I just did the same thing - moved array on top level of object passed into template =)
I have a list of object which are dynamically grouped which basically means I have a nested Array. We represent those in a spreadsheet into multiple groups of tables. our sample JSON : { "ParentName": "Testunt", "Description": "This is tEst Description Show me", "TesVal": "", "GroupedList": [ { "GroupName": "asdasddfs", "GroupList": [ { "TotalNumber": 23, "Qty": 1, "Code": "XYz" }, { "TotalNumber": 23, "Qty": 12, "Code": "WKP" } ] }, { "GroupName": "PUMPTYPEA", "GroupList": [ { "TotalNumber": 23, "Qty": 1, "Code": "SKP" }, { "TotalNumber": 23, "Qty": 1, "Code": "SXKP" } ] } ] }