edi9999 Github contribution chart
edi9999 Github Stats
edi9999 Most Used Languages

Activity

05 Oct 2022

Edi9999

Cannot read properties of undefined (reading 'lIndex') when parsing template

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : None needed
  • Runner : NodeJS

How to reproduce my problem :

My template is the following: template.zip

With the following js file :

const fs = require('fs');
const PizZip = require('pizzip');
const Docxtemplater = require('docxtemplater');

const content = fs
    .readFileSync(__dirname + "/template.zip", "binary");

const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {
  modules: [],
  delimiters: { start: "{{", end: "}}" },
})
console.log('Good');
//Execution does not reach this point, since it fails to parse the document 

I would expect it to :

  • not fail. The error message is:
TypeError: Cannot read properties of undefined (reading 'lIndex')
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:331:42
    at Array.some (<anonymous>)
    at LoopModule.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:322:15)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:226:24
    at Array.reduce (<anonymous>)
    at _postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:225:22)
    at postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:228:20)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:268:30
    at Array.reduce (<anonymous>)
    at Object.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:248:32) 

I noticed that this issue didn't appear in 3.30.0, and bisected the repo to found that the commit which introduced the bug was bccf18bf31a1212d7fbcb857839239605c36ea95

Forked On 05 Oct 2022 at 07:04:08

Edi9999

The template just contained

{{#ice}}{{/}} 

I'm not sure if you are expecting to get anything from this output, but I don't see what you wanted to achieve with this template ?

Commented On 05 Oct 2022 at 07:04:08
Create Branch

Edi9999

Generate docx, pptx, and xlsx from templates (Word, Powerpoint and Excel documents), from Node.js, the Browser and the command line / Demo: https://www.docxtemplater.com/demo. #docx #office #generator #templating #report #json #generate #generation #template #create #pptx #docx #xlsx #react #vuejs #angularjs #browser #typescript #image #html #table #chart

On 05 Oct 2022 at 07:03:03

Edi9999

Update dependencies

Pushed On 05 Oct 2022 at 07:02:58

Edi9999

Bugfix to correctly handle empty loop

Pushed On 05 Oct 2022 at 07:02:58

Edi9999

3.31.4

Pushed On 05 Oct 2022 at 07:02:58

Edi9999

Cannot read properties of undefined (reading 'lIndex') when parsing template

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : None needed
  • Runner : NodeJS

How to reproduce my problem :

My template is the following: template.zip

With the following js file :

const fs = require('fs');
const PizZip = require('pizzip');
const Docxtemplater = require('docxtemplater');

const content = fs
    .readFileSync(__dirname + "/template.zip", "binary");

const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {
  modules: [],
  delimiters: { start: "{{", end: "}}" },
})
console.log('Good');
//Execution does not reach this point, since it fails to parse the document 

I would expect it to :

  • not fail. The error message is:
TypeError: Cannot read properties of undefined (reading 'lIndex')
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:331:42
    at Array.some (<anonymous>)
    at LoopModule.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:322:15)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:226:24
    at Array.reduce (<anonymous>)
    at _postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:225:22)
    at postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:228:20)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:268:30
    at Array.reduce (<anonymous>)
    at Object.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:248:32) 

I noticed that this issue didn't appear in 3.30.0, and bisected the repo to found that the commit which introduced the bug was bccf18bf31a1212d7fbcb857839239605c36ea95

Forked On 05 Oct 2022 at 07:02:52

Edi9999

I've just fixed the issue in version v3.31.5

Commented On 05 Oct 2022 at 07:02:52

Edi9999

Cannot read properties of undefined (reading 'lIndex') when parsing template

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : None needed
  • Runner : NodeJS

How to reproduce my problem :

My template is the following: template.zip

With the following js file :

const fs = require('fs');
const PizZip = require('pizzip');
const Docxtemplater = require('docxtemplater');

const content = fs
    .readFileSync(__dirname + "/template.zip", "binary");

const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {
  modules: [],
  delimiters: { start: "{{", end: "}}" },
})
console.log('Good');
//Execution does not reach this point, since it fails to parse the document 

I would expect it to :

  • not fail. The error message is:
TypeError: Cannot read properties of undefined (reading 'lIndex')
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:331:42
    at Array.some (<anonymous>)
    at LoopModule.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/loop.js:322:15)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:226:24
    at Array.reduce (<anonymous>)
    at _postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:225:22)
    at postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/parser.js:228:20)
    at /home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:268:30
    at Array.reduce (<anonymous>)
    at Object.postparse (/home/marco/Walcu/pedefeprinter/docxtemplater/js/modules/expand-pair-trait.js:248:32) 

I noticed that this issue didn't appear in 3.30.0, and bisected the repo to found that the commit which introduced the bug was bccf18bf31a1212d7fbcb857839239605c36ea95

Forked On 05 Oct 2022 at 03:46:02

Edi9999

Thanks for reporting a detailed issue.

I will take a look and publish a fix within a few hours.

Commented On 05 Oct 2022 at 03:46:02

Edi9999

Remove postinstall script

Pushed On 01 Oct 2022 at 06:49:44

Edi9999

Update dependencies

Pushed On 01 Oct 2022 at 06:49:44

Edi9999

started

Started On 23 Sep 2022 at 08:00:33

Edi9999

Footnote reference is not in superscript and contains an extra "tab" before it's raw ooxml run

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : footnotes
  • Runner : Browser/Node.JS/... nodejs

How to reproduce my problem :

$ node footnote.mjs

My template is the following : (Upload the docx file here inside github, which you have to name template.zip (github doesn't accept the docx extension))

With the following js file :

import fs from 'node:fs'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

import Docxtemplater from 'docxtemplater'
import PizZip from 'PizZip'

import FootnoteModule from 'docxtemplater-footnote-module'

import expr from 'angular-expressions'
import assign from 'lodash/assign.js'

const __dirname = dirname(fileURLToPath(import.meta.url))
const templatePath = path.resolve(__dirname + '/examples/footnote.docx')
const tagsPath = path.resolve(__dirname + '/examples/footnote.json')

function parser (tag) {
  tag = tag
    .replace(/^\.$/, 'this')
    .replace(/(‘|’)/g, "'")
    .replace(/(“|”)/g, '"')
  const prog = expr.compile(tag)
  return {
    get: async function (scope, context) {
      const isIncludeTag =
        context?.meta?.part?.module === 'pro-xml-templating/include'
      let value = null
      if (tag === '.') {
        value = scope
      } else {
        value = prog(scope)
      }
      if (isIncludeTag && value) {
        await value.renderAsync(scope)
      }
      return value
    }
  }
}

function nullGetter (part, scopeManager) {
  if (!part.module) return `{{${part.value}}}`
  if (part.module === 'rawxml') return ''
  return ''
}

function loadTemplate (path, options) {
  const buffer = fs.readFileSync(path, 'binary')
  const zip = new PizZip(buffer)
  const template = new Docxtemplater(zip, options)
  return template
}

const createCommonOptions = () => ({
  delimiters: {
    start: '{{',
    end: '}}'
  },
  paragraphLoop: true,
  nullGetter,
  parser,
  modules: [
    new FootnoteModule({
      raw: true,
      refProperties: '<w:vertAlign w:val="superscript"/>'
    })
  ]
})

const service = loadTemplate(templatePath, createCommonOptions())
const tags = JSON.parse(fs.readFileSync(tagsPath, 'utf8'))
await service.renderAsync(tags)
const buffer = service.getZip().generate({ type: 'nodebuffer' })
fs.writeFileSync(__dirname + '/output.docx', buffer) 

I would expect it to :

Forked On 23 Sep 2022 at 07:23:13

Edi9999

Hello @nagaozen , please open this issue per email, this issue tracker is for the open source version, not for paid modules.

My email can be found on my profile : https://github.com/edi9999/

Thanks.

Commented On 23 Sep 2022 at 07:23:13

Edi9999

Merge Cell Columns on Full Table

Environment

  • Version of docxtemplater : 3.16.9
  • Used docxtemplater-modules : Table (Full and Merge)
  • Runner : Browser (through demos) - Chrome Version 105.0.5195.125

How to reproduce my problem :

My template is the following :

merge_template.zip

I would expect it to :

Merge the first 3 and the last 3 columns together as per the {:merge-cells-col 1,2,4} documentation as listed in the docs. Instead it gives the following error: The scope parser for the tag "1,2,3,8,9,10" failed to compile. Assumedly this is because there needs to be an iterable element represented in the template, and it won't just combine pre-made rows.

I was originally trying to create a table in Word that had a header something like this:

image

I had tried creating a Full Table using a data object (below), and then running it through the Merge functionality, but that wouldn't work as it just detected premade rows. An even better solution to this issue would be to add the {:merge-cells-col X} functionality to the Full Table module. We can almost get there by using just the Full Table module and the colspan property, but a way to merge identical vertical cells would be very useful.

{
  "table1": {
    "data": [
      [
        "Header 1",
        "Header 2",
        "Header 3",
        { "colspan":  4,
          "text": "Header 4"
        },
        "Header 5",
        "Header 6",
        "Header 7"
      ],
      [
        "Header 1",
        "Header 2",
        "Header 3",
        "Header 4.1",
        "Header 4.2",
        "Header 4.3",
        "Header 4.4",
        "Header 5",
        "Header 6",
        "Header 7"
      ]
    ],
    "size": [2, 10],
    "totalWidth": 700
  }
} 

I don't think this is something that can be achieved by just using the headers options in Full Table, but I could be missing something. Thank you!

Forked On 20 Sep 2022 at 09:37:48

Edi9999

Please use email for future requests concerning the paid modules, github issues are solely for the open source library.

Commented On 20 Sep 2022 at 09:37:48

Edi9999

Merge Cell Columns on Full Table

Environment

  • Version of docxtemplater : 3.16.9
  • Used docxtemplater-modules : Table (Full and Merge)
  • Runner : Browser (through demos) - Chrome Version 105.0.5195.125

How to reproduce my problem :

My template is the following :

merge_template.zip

I would expect it to :

Merge the first 3 and the last 3 columns together as per the {:merge-cells-col 1,2,4} documentation as listed in the docs. Instead it gives the following error: The scope parser for the tag "1,2,3,8,9,10" failed to compile. Assumedly this is because there needs to be an iterable element represented in the template, and it won't just combine pre-made rows.

I was originally trying to create a table in Word that had a header something like this:

image

I had tried creating a Full Table using a data object (below), and then running it through the Merge functionality, but that wouldn't work as it just detected premade rows. An even better solution to this issue would be to add the {:merge-cells-col X} functionality to the Full Table module. We can almost get there by using just the Full Table module and the colspan property, but a way to merge identical vertical cells would be very useful.

{
  "table1": {
    "data": [
      [
        "Header 1",
        "Header 2",
        "Header 3",
        { "colspan":  4,
          "text": "Header 4"
        },
        "Header 5",
        "Header 6",
        "Header 7"
      ],
      [
        "Header 1",
        "Header 2",
        "Header 3",
        "Header 4.1",
        "Header 4.2",
        "Header 4.3",
        "Header 4.4",
        "Header 5",
        "Header 6",
        "Header 7"
      ]
    ],
    "size": [2, 10],
    "totalWidth": 700
  }
} 

I don't think this is something that can be achieved by just using the headers options in Full Table, but I could be missing something. Thank you!

Forked On 20 Sep 2022 at 09:37:20

Edi9999

This update was not added to the demo, explaining why it doesn't work yet on the demo server.

Commented On 20 Sep 2022 at 09:37:20

Edi9999

Update dependencies

Pushed On 20 Sep 2022 at 09:31:09

Edi9999

Sub-template module to use multiple text resources in one Word DOC

We have been reviewing the sub-template module and understand we can put one text resource into one document with the {:include ...} path.

Our question is can we put two text resources into one document. For example,

We would want to write the following syntax:

{:include subtemplate:'header'}

{:include subtemplate:'footer'}

In this scenario both header and footer are stored in one document.

Is this possible now or would this need to be an extension?

Currently having to put each text resource into a unique Word document is not very efficient. We would want to organize the resources in documents with multiple resources.

Forked On 20 Sep 2022 at 09:05:13

Edi9999

Hello, I think I replied to quickly and I don't see a way to do this.

There is the segment module but that is to import parts of the current document, not from an external document.

Commented On 20 Sep 2022 at 09:05:13

Edi9999

Segments not working on nested templates

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : [docxtemplater-subtemplate-module]
  • Runner : nodejs

How to reproduce my problem :

My template is the following:

nested-root.docx:

Root Template
{{:include subtemplate}} 

nested-template.docx:

Middle Template
{{:include userslist}} 

segments.docx:

{{:segment profile}}
________________________________________
Name: {{fullname}},
Email: {{email}}
{{:segment/}}

{{#users}}
{{:includesegment profile}}
{{/}} 

With the following js file :

import fs from 'node:fs'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

import Docxtemplater from 'docxtemplater'
import SubTemplateModule from 'docxtemplater-subtemplate-module'
import PizZip from 'PizZip'

const SegmentModule = SubTemplateModule.Segment

import expr from 'angular-expressions'
import assign from 'lodash/assign.js'

const __dirname = dirname(fileURLToPath(import.meta.url))
const templatePath = path.resolve(__dirname + '/examples/nested-root.docx')
const tagsPath = path.resolve(__dirname + '/examples/segments.json')
const subtemplates = {
  subtemplate: path.resolve(__dirname + '/examples/nested-template.docx'),
  userslist: path.resolve(__dirname + '/examples/segments.docx')
}

function parser (tag) {
  tag = tag
    .replace(/^\.$/, 'this')
    .replace(/(‘|’)/g, "'")
    .replace(/(“|”)/g, '"')
  const prog = expr.compile(tag)
  return {
    get: function (scope, context) {
      const isIncludeTag =
        context?.meta?.part?.module === 'pro-xml-templating/include'
      let value = null
      if (tag === '.') {
        value = scope
      } else {
        value = prog(scope)
      }
      if (isIncludeTag && value) {
        value.render(scope)
      }
      return value
    }
  }
}

function nullGetter (part, scopeManager) {
  if (!part.module) return `{{${part.value}}}`
  if (part.module === 'rawxml') return ''
  return ''
}

function loadTemplate (path, options) {
  const buffer = fs.readFileSync(path, 'binary')
  const zip = new PizZip(buffer)
  const template = new Docxtemplater(zip, options)
  return template
}

const createCommonOptions = () => ({
  delimiters: {
    start: '{{',
    end: '}}'
  },
  paragraphLoop: true,
  nullGetter,
  modules: [new SubTemplateModule(), new SegmentModule()]
})

const service = loadTemplate(
  templatePath,
  Object.assign(createCommonOptions(), { parser })
)
const tags = JSON.parse(fs.readFileSync(tagsPath, 'utf8'))
Object.keys(subtemplates).forEach(id => {
  tags[id] = loadTemplate(subtemplates[id], createCommonOptions())
})
service.render(tags)
const buffer = service.getZip().generate({ type: 'nodebuffer' })

fs.writeFileSync(__dirname + '/output.docx', buffer) 

I would expect it to :

  • return the following template (please upload your generated document and expected document)
  • not fail (include error message)

template.zip generated-expected.zip

Forked On 20 Sep 2022 at 08:56:10

Edi9999

The github issue tracker is not for discussing issues on the paid product, that's why it is marked as completed but I will respond in a timely manner per email.

Commented On 20 Sep 2022 at 08:56:10

Edi9999

Segments not working on nested templates

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : [docxtemplater-subtemplate-module]
  • Runner : nodejs

How to reproduce my problem :

My template is the following:

nested-root.docx:

Root Template
{{:include subtemplate}} 

nested-template.docx:

Middle Template
{{:include userslist}} 

segments.docx:

{{:segment profile}}
________________________________________
Name: {{fullname}},
Email: {{email}}
{{:segment/}}

{{#users}}
{{:includesegment profile}}
{{/}} 

With the following js file :

import fs from 'node:fs'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

import Docxtemplater from 'docxtemplater'
import SubTemplateModule from 'docxtemplater-subtemplate-module'
import PizZip from 'PizZip'

const SegmentModule = SubTemplateModule.Segment

import expr from 'angular-expressions'
import assign from 'lodash/assign.js'

const __dirname = dirname(fileURLToPath(import.meta.url))
const templatePath = path.resolve(__dirname + '/examples/nested-root.docx')
const tagsPath = path.resolve(__dirname + '/examples/segments.json')
const subtemplates = {
  subtemplate: path.resolve(__dirname + '/examples/nested-template.docx'),
  userslist: path.resolve(__dirname + '/examples/segments.docx')
}

function parser (tag) {
  tag = tag
    .replace(/^\.$/, 'this')
    .replace(/(‘|’)/g, "'")
    .replace(/(“|”)/g, '"')
  const prog = expr.compile(tag)
  return {
    get: function (scope, context) {
      const isIncludeTag =
        context?.meta?.part?.module === 'pro-xml-templating/include'
      let value = null
      if (tag === '.') {
        value = scope
      } else {
        value = prog(scope)
      }
      if (isIncludeTag && value) {
        value.render(scope)
      }
      return value
    }
  }
}

function nullGetter (part, scopeManager) {
  if (!part.module) return `{{${part.value}}}`
  if (part.module === 'rawxml') return ''
  return ''
}

function loadTemplate (path, options) {
  const buffer = fs.readFileSync(path, 'binary')
  const zip = new PizZip(buffer)
  const template = new Docxtemplater(zip, options)
  return template
}

const createCommonOptions = () => ({
  delimiters: {
    start: '{{',
    end: '}}'
  },
  paragraphLoop: true,
  nullGetter,
  modules: [new SubTemplateModule(), new SegmentModule()]
})

const service = loadTemplate(
  templatePath,
  Object.assign(createCommonOptions(), { parser })
)
const tags = JSON.parse(fs.readFileSync(tagsPath, 'utf8'))
Object.keys(subtemplates).forEach(id => {
  tags[id] = loadTemplate(subtemplates[id], createCommonOptions())
})
service.render(tags)
const buffer = service.getZip().generate({ type: 'nodebuffer' })

fs.writeFileSync(__dirname + '/output.docx', buffer) 

I would expect it to :

  • return the following template (please upload your generated document and expected document)
  • not fail (include error message)

template.zip generated-expected.zip

Forked On 20 Sep 2022 at 08:35:32

Edi9999

The email address can be simply found at https://github.com/edi9999/

Commented On 20 Sep 2022 at 08:35:32

Edi9999

Segments not working on nested templates

Environment

  • Version of docxtemplater : 3.31.3
  • Used docxtemplater-modules : [docxtemplater-subtemplate-module]
  • Runner : nodejs

How to reproduce my problem :

My template is the following:

nested-root.docx:

Root Template
{{:include subtemplate}} 

nested-template.docx:

Middle Template
{{:include userslist}} 

segments.docx:

{{:segment profile}}
________________________________________
Name: {{fullname}},
Email: {{email}}
{{:segment/}}

{{#users}}
{{:includesegment profile}}
{{/}} 

With the following js file :

import fs from 'node:fs'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

import Docxtemplater from 'docxtemplater'
import SubTemplateModule from 'docxtemplater-subtemplate-module'
import PizZip from 'PizZip'

const SegmentModule = SubTemplateModule.Segment

import expr from 'angular-expressions'
import assign from 'lodash/assign.js'

const __dirname = dirname(fileURLToPath(import.meta.url))
const templatePath = path.resolve(__dirname + '/examples/nested-root.docx')
const tagsPath = path.resolve(__dirname + '/examples/segments.json')
const subtemplates = {
  subtemplate: path.resolve(__dirname + '/examples/nested-template.docx'),
  userslist: path.resolve(__dirname + '/examples/segments.docx')
}

function parser (tag) {
  tag = tag
    .replace(/^\.$/, 'this')
    .replace(/(‘|’)/g, "'")
    .replace(/(“|”)/g, '"')
  const prog = expr.compile(tag)
  return {
    get: function (scope, context) {
      const isIncludeTag =
        context?.meta?.part?.module === 'pro-xml-templating/include'
      let value = null
      if (tag === '.') {
        value = scope
      } else {
        value = prog(scope)
      }
      if (isIncludeTag && value) {
        value.render(scope)
      }
      return value
    }
  }
}

function nullGetter (part, scopeManager) {
  if (!part.module) return `{{${part.value}}}`
  if (part.module === 'rawxml') return ''
  return ''
}

function loadTemplate (path, options) {
  const buffer = fs.readFileSync(path, 'binary')
  const zip = new PizZip(buffer)
  const template = new Docxtemplater(zip, options)
  return template
}

const createCommonOptions = () => ({
  delimiters: {
    start: '{{',
    end: '}}'
  },
  paragraphLoop: true,
  nullGetter,
  modules: [new SubTemplateModule(), new SegmentModule()]
})

const service = loadTemplate(
  templatePath,
  Object.assign(createCommonOptions(), { parser })
)
const tags = JSON.parse(fs.readFileSync(tagsPath, 'utf8'))
Object.keys(subtemplates).forEach(id => {
  tags[id] = loadTemplate(subtemplates[id], createCommonOptions())
})
service.render(tags)
const buffer = service.getZip().generate({ type: 'nodebuffer' })

fs.writeFileSync(__dirname + '/output.docx', buffer) 

I would expect it to :

  • return the following template (please upload your generated document and expected document)
  • not fail (include error message)

template.zip generated-expected.zip

Forked On 20 Sep 2022 at 08:34:52

Edi9999

Hello, I'm happy to fix your issue, however for the subsection module, you have to send an email with the email that you used during your purchase. Can you please do that ?

Commented On 20 Sep 2022 at 08:34:52

Edi9999

Merge Cell Columns on Full Table

Environment

  • Version of docxtemplater : 3.16.9
  • Used docxtemplater-modules : Table (Full and Merge)
  • Runner : Browser (through demos) - Chrome Version 105.0.5195.125

How to reproduce my problem :

My template is the following :

merge_template.zip

I would expect it to :

Merge the first 3 and the last 3 columns together as per the {:merge-cells-col 1,2,4} documentation as listed in the docs. Instead it gives the following error: The scope parser for the tag "1,2,3,8,9,10" failed to compile. Assumedly this is because there needs to be an iterable element represented in the template, and it won't just combine pre-made rows.

I was originally trying to create a table in Word that had a header something like this:

image

I had tried creating a Full Table using a data object (below), and then running it through the Merge functionality, but that wouldn't work as it just detected premade rows. An even better solution to this issue would be to add the {:merge-cells-col X} functionality to the Full Table module. We can almost get there by using just the Full Table module and the colspan property, but a way to merge identical vertical cells would be very useful.

{
  "table1": {
    "data": [
      [
        "Header 1",
        "Header 2",
        "Header 3",
        { "colspan":  4,
          "text": "Header 4"
        },
        "Header 5",
        "Header 6",
        "Header 7"
      ],
      [
        "Header 1",
        "Header 2",
        "Header 3",
        "Header 4.1",
        "Header 4.2",
        "Header 4.3",
        "Header 4.4",
        "Header 5",
        "Header 6",
        "Header 7"
      ]
    ],
    "size": [2, 10],
    "totalWidth": 700
  }
} 

I don't think this is something that can be achieved by just using the headers options in Full Table, but I could be missing something. Thank you!

Forked On 20 Sep 2022 at 12:15:09

Edi9999

Hello @sarahlegeza , this is something that was a bug, I have now fixed this in version 3.16.10.

Commented On 20 Sep 2022 at 12:15:09

Edi9999

$index is only yielding 0 - can't get the proper scope

Environment

  • Version of docxtemplater : 3.31.2
  • Used docxtemplater-modules : -
  • Runner : Vue.js

How to reproduce my problem :

My template is the following :

{#passengers}
  {#passengers.length>1}
    {$index}
  {/}
{/} 

With the following js file : standard angular parser as in docs. No custom mods.

const fs = require('fs');
const Docxtemplater = require('docxtemplater');

const content = fs
    .readFileSync(__dirname + "/template.zip", "binary");

const zip = new PizZip(content);
const doc = new Docxtemplater(zip)

doc.render({
	( INSERT YOUR DATA HERE )
});

const buf = doc.getZip()
             .generate({type:"nodebuffer"});

fs.writeFileSync(__dirname+"/output.docx",buf); 

I would expect it to :

  • return the following indices (as in 1,2,3...etc.) for each item in passengers array. Instead I get zero for every iteration. Only show index value if passengers have more than one item.

Forked On 20 Sep 2022 at 10:37:09

Edi9999

Can you try instead :

{#passengers}
  {passengers.length>1 ? $index : ""}
{/} 

The problem is that the "{$index}" refers to the index of the current section, and in your example the parent section of the {$index} tag was a child of the {#passengers.length>1} tag.

Commented On 20 Sep 2022 at 10:37:09
Issue Comment

Edi9999

Types introduced in 3.1.2 are incorrect

Most notably:

  • new PizZip(contents) exists in @types/pizzip but not in packaged types
  • PizZip.load(contents) exists in packaged types but doesn't exist in the code. Need to use zipInstance.load(contents)
  • file.async('nodebuffer') exists in packaged types but doesn't exist in the code

The following types were working great until now: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pizzip/index.d.ts

Forked On 20 Sep 2022 at 10:21:47

Edi9999

I have just released version 3.1.3, it should be better now.

Commented On 20 Sep 2022 at 10:21:47
Create Branch

Edi9999

A synchronous zip module

On 20 Sep 2022 at 10:21:39

Edi9999

Update typing file

Pushed On 20 Sep 2022 at 10:21:37

Edi9999

3.1.3

Pushed On 20 Sep 2022 at 10:21:37
Create Branch

Edi9999

A synchronous zip module

On 19 Sep 2022 at 02:35:37

Edi9999

Update dependencies and fix tests

Pushed On 19 Sep 2022 at 02:35:35

Edi9999

Add typings files

Pushed On 19 Sep 2022 at 02:35:35

Edi9999

Update CHANGES

Pushed On 19 Sep 2022 at 02:35:35

Edi9999

3.1.2

Pushed On 19 Sep 2022 at 02:35:35

Edi9999

started

Started On 19 Sep 2022 at 12:52:57

Edi9999

Update dependencies

Pushed On 15 Sep 2022 at 08:40:30