Skip to content

Loop horizontally when generating an XLSX file #601

Closed
@vdechef

Description

@vdechef

Environment

  • Version of docxtemplater : 3.21.1
  • Used docxtemplater-modules :
    • docxtemplater-footnote-module: 3.1.4
    • docxtemplater-html-module: 3.25.0
    • docxtemplater-html-pptxmodule: 3.2.0
    • docxtemplater-image-module: 3.8.3
    • docxtemplater-slides-module: 3.2.9
    • docxtemplater-subtemplate-module: 3.6.1
    • docxtemplater-wrun-module: 3.1.1
    • docxtemplater-xlsx-module: 3.4.1
  • Runner : Browser with Vue.js

How to reproduce my problem :

I need to generate an excel file containing the list of children per school.
I want to obtain something like this in Excel:

id Dpt Firstname Lastname age level Firstname Lastname age level
School A 31 Henri IV 12 6ème Louis Le Gros 6 CP
School B 64 Marie-Antoinette d'Autriche 10 CM2 Hubert de Montmirail 17 Terminale

Each school has to be on 1 line, with the kids firstname, lastname, age, and level one after the other.
This file will then be imported automatically on an other application, so I cannot modify its format (I need to stick to the application import format).

My data is something like this:

const schools = [
            {
                id: "School A",
                department: "31",
                students: [
                    {
                        firstname: "Henri",
                        lastname: "IV",
                        age: 12,
                        level: "6ème"
                    },
                    {
                        firstname: "Louis",
                        lastname: "Le Gros",
                        age: 6,
                        level: "CP"
                    }
                ]
            },
            {
                id: "School B",
                department: "64",
                students: [
                    {
                        firstname: "Marie-Antoinette",
                        lastname: "d'Autriche",
                        age: 10,
                        level: "CM2"
                    },
                    {
                        firstname: "Hubert",
                        lastname: "de Monmtirail",
                        age: 17,
                        level: "Terminale"
                    }
                ]
            }
        ]

I know I can make a template like this:

{#schools}{id} | {department} | {students[0].firstname} | {students[1].firstname} | {students[2].firstname} | {/schools}

But I may have thousands of students, and some complex conditions for each cell, so it is very tedious.

Would i be possible to have a dedicated tag or pipe in XLSX module to fill cells on a row ? This would not insert columns, but fill cells, overwriting existing content if any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions