We created the document template as suggested by Fedor and it looks great, however we seem to have a problem with the sort function: As soon as we sort on a more than 1 level deep association it throws an exception, even though it can print that column to our sheet no problem. Is this a known problem? Is there anything we can do to fix this? As it seems from the debug the problem is that the ORDER BY clause of the query only says 'ORDER BY FIELDNAME', not 'ORDER BY TABLE.FIELDNAME'?
Where exactly did you sort the object? I tried to recreate your issue. In the microflow that generates the document (I created a pdf), I retrieve (a list of) the object from the database, and in this retrieve action I sort on an association two levels deep. By doing this I did not receive an error...
Turns out this was quite likely a Bug in 2.5.1, all fine after upgrade to 2.5.3