Categories > OpenTBS with DOCX >

Corrupt DOCX trying after trying to OPENTBS_CHART

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Wogan
Date: 2016-12-05
Time: 14:02

Corrupt DOCX trying after trying to OPENTBS_CHART

I'm trying to use TBS to update the values in an existing chart. It's not a very complex block of code:

$scores = [
  ["Category 1","Category 2","Category 3","Category 4"],
  [0.5, 1.3, 2.7, 6.6]
];
       
$TBS->PlugIn(OPENTBS_CHART, "chart1", 1, $scores);

The generated document is apparently "corrupt" - I get a warning in Word: "The file is corrupt and cannot be opened". If I then click OK, it asks if I want to recover the contents of the document. If I select Yes, it then opens the document, with the chart correctly populated.

I've tried all 3 variations of key/value pairs to input data. Any idea what I'm doing wrong?
By: Wogan
Date: 2016-12-05
Time: 14:25

Re: Corrupt DOCX trying after trying to OPENTBS_CHART

I think I know why the problem is happening, just not how to fix it.

When I create the document in Word (2013), it embeds an xlsx document within the docx to hold the chart data. That xlsx file vanishes after OpenTBS tries rendering the template.

It looks like, in order to safely modify the numbers inside the chart, I need to load the Excel document within the docx archive and modify that directly instead. I'm trying to figure that out now.
By: Skrol29
Date: 2016-12-06
Time: 15:11

Re: Corrupt DOCX trying after trying to OPENTBS_CHART

Hello Wogan

When you build a chart in a DOCX, Ms Word saves an extra data in an embedded XSLX.
But this XLSX is duplicate and only used for editing data. The true data of the chart are saved with the chart.
OpenTBS merges the data in the chart and delete the XSLX, otherwise the XLSX does not correspond with the chart any more.

I think you problem comes from something else.
By: Wogan
Date: 2016-12-06
Time: 16:53

Re: Corrupt DOCX trying after trying to OPENTBS_CHART

I don't think that's the problem. I built a script to do nothing but modify a chart, and built a document that only contained a chart, and I couldn't get that to work either.

I tried saving the document in both Microsoft Word format, and strict OOXML format, with no difference.

In addition: I opened a corrupted document, Word recovered it, I saved it, then used that document as a template again. This time, TBS could see the chart but couldn't make any more changes to it.

In the end, I solved this problem by modifying the internal XLSX file, and by replacing the XML block inside the chart.xml object. My use case is very very specific, so this is an acceptable workaround for now.
By: Skrol29
Date: 2016-12-06
Time: 18:07

Re: Corrupt DOCX trying after trying to OPENTBS_CHART

Would it be possible for you to send to me something to reproduce the problem ?