carboneio / carbone

Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
https://carbone.io
Other
1.28k stars 189 forks source link

TypeError: Cannot read property 'position' of undefined (Bi-directional loop) #45

Open baktash93 opened 5 years ago

baktash93 commented 5 years ago

Greetings. I am trying to use the bi-directional loop with an .odt file but can't seem to get it working as I've started with the provided examples in the docs but it doesn't work as expected and produces the following error:

TypeError: Cannot read property 'position' of undefined
at Object.splitMarkers (<project>/node_modules/carbone/lib/extracter.js:228:41)
at <project>/node_modules/carbone/lib/builder.js:41:50
at Object.preprocessMarkers (<project>/node_modules/carbone/lib/parser.js:286:5)
at <project>/node_modules/carbone/lib/builder.js:38:18
at <project>/node_modules/carbone/lib/parser.js:39:7
at process._tickCallback (internal/process/next_tick.js:61:11)

Environment information:

Angular v8 LibreOffice calc generation .odt template Node.js 10.15.0

Your quick response and help is very much appreciated.

Dobby85 commented 5 years ago

Hi, can you give your template and your sample JSON so we can try to reproduce it ?

baktash93 commented 5 years ago

Yeah sure, the .odt is the same as the one from the online example:

 {d[i].models[i].brand} | {d[i+1].models[i].brand}
 {d[i].models[i].name} | {d[i+1].models[i].name}
 {d[i].models[i+1].name } | {d[i+1].models[i+1].name }

And the data supplied to the .odt is as follows:

[
  {
    "brand" : "Toyota",
    "models": [ 
      {"name" : "Prius 2" }, 
      {"name" : "Prius 3" }
    ]
  },
  {
    "brand" : "Tesla",
    "models" : [ 
      {"name" : "S" }, 
      {"name" : "X" }
    ]
  },
  {
    "brand" : "Lumeneo",
    "models" : [ 
      {"name" : "Smera" }, 
      {"name" : "Néoma" }
    ]
  }
]
Dobby85 commented 5 years ago

It looks like there is a bug with that... We already know bi-directional loop does not work in .ods file. We will try to find a solution as soon as possible!

baktash93 commented 5 years ago

OK looking forward to it.

steevepay commented 4 years ago

Hi @baktash93

Just to give you some updates, we will fix this issue maybe on the next release. If you can't wait the fix, feel free to fork the project and contribute :)

JosselinTD commented 4 years ago

I had it working with this :

{d.title[i].text} {d.title[i+1].text}
{d.content[i].content[i].text} {d.content[i].content[i+1].text}
{d.content[i+1].content[i].text} {d.content[i+1].content[i+1].text}
{
  title: [{text: 'Salutation'}, {text: 'lang'}],
  content: [
    {content: [{text: 'Hello'}, {text: 'en'}]},
    {content: [{text: 'Bonjour'}, {text: 'fr'}]}
  ]
}

I never use a direct value from an array. Array contains Object which contains the value to use.

For the doc example, try by using something like that :

{
  myArray : [{"brand": etc...}, {"brand": etc...]
}

and changing the template with d.myArray[i]

waltermaldonado commented 4 years ago

I had it working with this :

{d.title[i].text} {d.title[i+1].text} {d.content[i].content[i].text} {d.content[i].content[i+1].text} {d.content[i+1].content[i].text} {d.content[i+1].content[i+1].text}

{
  title: [{text: 'Salutation'}, {text: 'lang'}],
  content: [
    {content: [{text: 'Hello'}, {text: 'en'}]},
    {content: [{text: 'Bonjour'}, {text: 'fr'}]}
  ]
}

I never use a direct value from an array. Array contains Object which contains the value to use.

For the doc example, try by using something like that :

{
  myArray : [{"brand": etc...}, {"brand": etc...]
}

and changing the template with d.myArray[i]

I managed to make it work like the example, but if you add another column to the data it does not get rendered...

chrisdlim commented 4 years ago

I had it working with this :

{d.title[i].text} {d.title[i+1].text} {d.content[i].content[i].text} {d.content[i].content[i+1].text} {d.content[i+1].content[i].text} {d.content[i+1].content[i+1].text}

{
  title: [{text: 'Salutation'}, {text: 'lang'}],
  content: [
    {content: [{text: 'Hello'}, {text: 'en'}]},
    {content: [{text: 'Bonjour'}, {text: 'fr'}]}
  ]
}

I never use a direct value from an array. Array contains Object which contains the value to use.

For the doc example, try by using something like that :

{
  myArray : [{"brand": etc...}, {"brand": etc...]
}

and changing the template with d.myArray[i]

Correct me if i'm wrong but..that example isn't using bi-directional looping is it? Isn't this just iterating 2 different arrays, one array in the header cells and one array for the data cells?

officeutils commented 3 years ago

This feature does not work at all. For .docx files too. Remove it from your documentation. You stole a lot of my time folks. Only 2 years have passed since the error was detected

steevepay commented 3 years ago

Hello @officeutils, thank you for reaching us.

The bi-directional loop depends significantly on the XML coming from the document. If a table is badly formed, Carbone will have difficulty in recognizing the elements to be repeated. Nevertheless, we will address the issue in the next few days to fully manage the recognition and creation of repeatable fields.

Could you please share your template and a JSON dataset without confidential information at "support@carbone.io"? Include on the template the strict minimum to reproduce the issue. We will use it in our testing.

officeutils commented 3 years ago

@steevepay I sent the all info to support. Thank you very much.

officeutils commented 2 years ago

@steevepay Is there any update here?

steevepay commented 2 years ago

Hello @officeutils, we need more time to solve bi-directional loops and it can't be solved in the coming sprints. We will share updates on the feed as soon as we work on it.

samirotiv commented 2 years ago

Spent two hours trying to get it to work and then found this thread. Any update on this or any workarounds?

officeutils commented 2 years ago

@samirotiv I found a temporary solution for my problem. I need to create multiple tables with 2-4 columns. Look at the attached picture. image

dvernole commented 2 years ago

Any news about this issue?

enariavishenda commented 2 years ago

delete from the main documentation, misled me, spent half a day

dgrelaud commented 1 year ago

Carbone v4.8.0 fixes lot of issues for bidirectional loop in DOCX templates.

The website has been updated: https://carbone.io/documentation.html#bi-directionnal-loop

Here is a real life example:

We keep this issue opened. When Carbone v5 will be available. This repository will be updated with Carbone v4 and we will close this issue.

Feel free to contact us on the chat of the website if you need further help & information.

https://carbone.io/examples/bidirectional-loop/bidirectional-loop.zip

capture