Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add a nested table rows generation support #82

Open
t0lik opened this issue Aug 27, 2019 · 13 comments
Open

Please add a nested table rows generation support #82

t0lik opened this issue Aug 27, 2019 · 13 comments

Comments

@t0lik
Copy link

t0lik commented Aug 27, 2019

изображение

In this examle we will see no table at all in the result docx even if we have objects in the "table" array.

Please add support for nested tables,

@gkiszczak
Copy link

+1 for this request. I've tried to fill nested table also.

@wlydhub
Copy link

wlydhub commented Sep 11, 2019

+1 for this request. I've tried to fill nested table also.
nead a
image

@achaird1
Copy link

+1 please add nested table support

@bfo2ses
Copy link

bfo2ses commented Apr 9, 2020

👍
Thanks for the lib by the way

@tomspeed22
Copy link

+1 to add this. Thanks

@jeopratama
Copy link

jeopratama commented Sep 28, 2020

+1 bump

@chaosforfun
Copy link

+1 , i want this feature, thanks

@pkozul
Copy link

pkozul commented Mar 10, 2022

In case it helps anyone, I got nested table working. There is a catch though, You need to have some space at the bottom of the nested table.

Here is the template I used:

image

Below is the result:

image

As you can see, the first 2 tables rendered just fine, but the last one did not render at all.

I am not sure if this is a limitation with docx-templates or MS Word.

@pkozul
Copy link

pkozul commented Mar 10, 2022

I modified the code and got it working. Not sure if this change would affect other scenarios, but now all 3 of the tables are being rendered fine. I added the code outlined in red (in the file processTemplate.js).

image

Below is the code I added, if anyone needs it for copy/paste:

// If the last generated output node is a table row, and it is set to be deleted,
// don't delete if it has exactly one nested row (i.e. within nested table)
if (tag === 'w:tr' && fRemoveNode) {
    fRemoveNode = (nodeIn._children.filter(child => child._tag === 'w:tr').length !== 1);
}

Below is the output:

image

@jjhbw
Copy link
Collaborator

jjhbw commented Mar 10, 2022

@pkozul thanks for looking into this! Can you make a PR with this change? I'd like to look into it further. If you can also add that template so I can make it into a test case, that would also be great.

@pkozul
Copy link

pkozul commented Mar 15, 2022

@jjhbw Bummer. Although my code change worked in this example I included above, it doesn't work in the more complex scenario I have at work. I'm not familiar enough with how the entire code works, so maybe you'll have some ideas on what else we can try?

I think it really comes down to the code I have outlined in the red box, and determining the exact condition required to NOT remove the w:tr node if it contains (dynamically generated) content.

@jjhbw
Copy link
Collaborator

jjhbw commented Mar 19, 2022

I'm out of ideas honestly. The docx spec is just too complex and too dependent on MS Word's secret sauce (MS trustbusters should have paid attention to this long ago).

At work we have had great success in achieving roughly what you want by inserting complex tables like the one below as HTML (using docx-templates). MS Word supports a good ~80% of the HTML spec surrounding <table/> elements and associated style rules. Note that support is not guaranteed (or nonexistent) with other docx readers, like LibreOffice.

I'm sorry to dissappoint. Happy to entertain ideas on how to solve this, though, but I'm all out myself.

@jjhbw jjhbw pinned this issue Jun 13, 2022
@naifxe
Copy link

naifxe commented Oct 14, 2024

+1 , to add, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests