guigrpa / docx-templates

Template-based docx report creation
MIT License
912 stars 145 forks source link

Unique table cells are removed if they evaluate a falsy condition #382

Open blancham opened 2 months ago

blancham commented 2 months ago

What

I found a regression introduced since v4.12.0, table cells that contains a condition that is evaluated as falsy are removed when templating (it was not the case in v4.11.5)

Steps to reproduce

NOTE: my delimiter is ## I have a table in my docx file that looks like this : Screenshot 2024-08-30 at 12 27 19

In v4.11.5 the cells are empty (because the condition is falsy), that's what we want : Screenshot 2024-08-30 at 12 28 31

But when I upgraded to v4.13.0 I found that this was not quite the case anymore : Screenshot 2024-08-30 at 12 27 29

After investigating, v4.12.0 seems to be the culprit.

Code

import createReport from 'docx-templates';
import fs from 'fs';

const template = fs.readFileSync('template.docx');

const buffer = await createReport({
  template,
  cmdDelimiter: "##",
});

fs.writeFileSync('output.docx', buffer)

output-4.11.5.docx output-4.13.0.docx template.docx

SuchiraD commented 1 month ago

@blancham , were you able to find a work around?

blancham commented 1 month ago

Unfortunately (for you) I didn't even try, I downgraded my version.. 🙄