jsreport - handlebars - Xlsx 食谱:使用模板时添加图像失败

jsreport - handlebars - Xlsx Recipe: add image fail when using a template

Xlsx 秘诀:使用模板时添加图片失败

它适用于空示例,但如果我上传模板,我会收到错误消息:

Error while executing templating engine. Cannot read property 'r:id' of undefined. Error on line 270:98.

  268 |     var drawingFullName
  269 |     if (this.ctx.root.$xlsxTemplate['xl/worksheets/' + sheetFullName].worksheet.drawing) {
> 270 |       var rid = this.ctx.root.$xlsxTemplate['xl/worksheets/' + sheetFullName].worksheet.drawing.$['r:id']
      |                                                                                                  ^
  271 |       this.ctx.root.$xlsxTemplate['xl/worksheets/_rels/' + sheetFullName + '.rels'].Relationships.Relationship.forEach(function (r) {
  272 |         if (r.$.Id === rid) {
  273 |           drawingFullName = r.$.Target.replace('../drawings/', '')


logs:
+0      Starting rendering request 987 (user: null)
+3      Rendering template { name: excel-image, recipe: xlsx, engine: handlebars, preview: true }
+4      Inline data specified.
+5      Resources not defined for this template.
+11     Base url not specified, skipping its injection.
+11     Rendering engine handlebars
TypeError: Cannot read property 'r:id' of undefined
    at Object.ensureDrawingOnSheet (evaluate-template-engine-helpers.js:270:98)
    at Object.addImage (evaluate-template-engine-helpers.js:345:48)
    at Object.<anonymous> (evaluate-template-engine-helpers.js:429:17)
    at Object.eval [as main] (eval at createFunctionContext (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:257:23), <anonymous>:5:89)
    at main (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
    at ret (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
    at ret (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
    at /app/node_modules/jsreport-handlebars/lib/handlebarsEngine.js:33:20
    at Object.base.apply (/app/node_modules/vm2/lib/contextify.js:469:32)
    at evaluate-template-engine.js:1:64

此错误发生的原因很简单,就是使用 jsreport 提供的示例代码添加图像,然后在 google 驱动器上创建空的 xlsx 文件 > 下载它 > 作为模板上传并将其包含在报告中。

请参考这个https://playground.jsreport.net/w/anon/nDSs3WAd

看起来我没有做错任何事,但文件格式与他们预期的不同,问题将在下一个版本中修复,他们在论坛中回答:

https://forum.jsreport.net/topic/1410/xlsx-recipe-add-image-fail-when-using-a-template/5

我就把这个留在这里供参考...