open-xml-templating / docxtemplater

Generate docx, pptx, and xlsx from templates (Word, Powerpoint and Excel documents), from Node.js or the browser. 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
https://www.docxtemplater.com
Other
3.07k stars 350 forks source link

The generated docx file is corrupted #552

Open ching2018 opened 4 years ago

ching2018 commented 4 years ago

image

{
        ACCOUNT_ID: 1699,
        ACCOUNT_DETAIL: [
          {
            CATEGORY: "Cat1",
            DETAIL: [
              {
                TRANS_ID: 1,
                DATE_: 930305,
                TYPE: "ABC",
                AMOUNT: 5224
              },
              {
                TRANS_ID: 2,
                DATE_: 930305,
                TYPE: "XYZ",
                AMOUNT: 2234
              }
            ]
          },
          {
            CATEGORY: "Cat2",
            DETAIL: [
              {
                TRANS_ID: 6,
                DATE_: 930114,
                TYPE: "ZXC",
                AMOUNT: 800
              },
              {
                TRANS_ID: 7,
                DATE_: 930114,
                TYPE: "ABC",
                AMOUNT: 600
              }
            ]
          }
        ]
      }

loop-table.docx

edi9999 commented 4 years ago

I confirm this corruption in this case.

I don't know yet exactly why it happens, I have to investigate further.

ching2018 commented 4 years ago

Thanks a lot!

edi9999 commented 4 years ago

Hello again,

Could you please explain what you would want to have as the output ?

The ACCOUNT_DETAIL loop will create one row for each element of the ACCOUNT_DETAIL array.

The $isLast loop will put either "." or ";", and it will put ";" for almost all ACCOUNT_DETAIL elements except for the last ACCOUNT_DETAIL loop

However, it is not clear to me what you want to achieve with the DETAIL loop.

In docxtemplater, when a loop tag starts in a table cell and ends in another table cell, the loop will be expanded to a table row, which means that it will create a row for each element in the array.

However, with the placement of your tags, it is I think not what you want.

This is still a bug, the docx should not get corrupted, a proper error should be shown if we want to error because this is an invalid usage of loop.

ching2018 commented 4 years ago

551

The two problems are the same, and my goal is to merge the cells in the loop. I look forward to seeing you implement this feature soon, and I will buy it. I'm sure that's what many people need.