英文:
JSReport -- working with docxChild. I can't resolve the error : "docxChild helper requires asset parameter to be set"
问题
我正在尝试在jsReport和Word上实现多种功能,并在这个问题上遇到了困难。
我想要创建一个可在不同模板中使用的资源,假设我的资源包含了正确的数据。
使用这个文档和UI jsReport Studio
,我创建了一个名为test-word
的工作模板,上传了一个带有一些handlebar的docx test_jsReport.docx
,创建了一些数据并使其正常工作。
然后,我在同一个文件夹中创建了一个资源,其中包含第二个docx test_jsReport2.docx
;并添加了一些代码,尝试单独生成它,使用相同的数据,这次也成功了。
到这一步,我的项目看起来像这样:
test project
然后,使用这个章节,我在我的docx test_jsReport.docx
中添加了以下代码:{{docxChild "test_jsReport2.docx"}}
。
所以我不能再运行我的报告了,错误如下。
Report "test-word" render failed.
Error while executing docx recipe
(because) error when evaluating engine handlebars for template anonymous
(because) "docxChild" helper call failed
(because) docxChild helper requires asset parameter to be set
(system-helpers.js line 706:11)
704 |
705 | if (assetNamePathOrObject == null) {
> 706 | throw a Error('docxChild helper requires asset parameter to be set')
| ^
707 | }
708 |
709 | const docxChildInfo = {}
我需要设置的是什么资源参数?如何设置它?
我相当肯定我应该以某种方式声明两个报告之间的链接,但我找不到如何做。
首先,我尝试在jsReport Studio中使用我的报告的资源属性,如下:
但它不起作用,而且我从来没有真正相信它,我认为它是用于定义与我修改的物理docx的链接的选项,这样我就不必在每次保存后上传。
其次,我阅读并尝试模仿文档中可以找到的一些其他系统,比如这个和那个,但这是用于HTML报告而不是Word。
最后,我尝试引用我的报告,使用以下脚本:
const jsreport = require('jsreport-proxy')
// 使用"beforeRender"或"afterRender"挂钩
// 以操作和控制报告生成
async function beforeRender (req, res) {
await jsreport.assets.registerHelpers('test_jsReport2.js')
}
这也不起作用。
我有点迷茫,使用docxChild
的正确方式是什么?
以下是我所做的示例链接:https://playground.jsreport.net/w/anon/Pm_vIEwF
这是我设置示例的方法:
- 准备好我的两个Word文件
- 右键单击>新建实体>模板
- 选择handlebars和docx>下一步>下一步
- 单击我的模板>在属性中,在docx中上传我的main.docx
- 右键单击>新建实体>资源>上传,我放入了我的subreport.docx
英文:
I'm trying many functionality on jsReport and word and got stuck on this one.
I want to create an asset usable in different template, assuming that my asset got the right data.
Using this documentation and the UI jsReport Studio
I create a working template called test-word
, I upload a docx test_jsReport.docx
with some ahnddlebar in it, create some data and it work.
Then I create an asset, in the same folder, with a second docx test_jsReport2.docx
; put some code and try to generate it alone with the same data, it worked again.
At this point my project look like this :
test project
Then, using this chapter I add in my docx test_jsReport.docx the following code : {{docxChild "test_jsReport2.docx"}}
.
So I can no longer run my report, the error is the following.
Report "test-word" render failed.
Error while executing docx recipe
(because) error when evaluating engine handlebars for template anonymous
(because) "docxChild" helper call failed
(because) docxChild helper requires asset parameter to be set
(system-helpers.js line 706:11)
704 |
705 | if (assetNamePathOrObject == null) {
> 706 | throw new Error('docxChild helper requires asset parameter to be set')
| ^
707 | }
708 |
709 | const docxChildInfo = {}
What is that aset parameter that I need to set ? And how to do it ?
I'm pretty sure that I should omehow declare some kind of link beween my two reports, but I can't find how to do that.
First I tried to use the asset property in jsReport studio on my report, like this :
But it doesn't worked and I never really believe it, I think it's an option to define a link to the physical docx I modify, so I don't have to upload after each save.
Second I read and try to mimic some other systems I can find in the doc like this and that and but it's for HTML report not word.
Lastly I tried to reference my report using a script like this :
const jsreport = require('jsreport-proxy')
// Use the "beforeRender" or "afterRender" hook
// to manipulate and control the report generation
async function beforeRender (req, res) {
await jsreport.assets.registerHelpers('test_jsReport2.js')
}
It doesn't work either.
I'm a little lost here, what is the right way to use docxChild ?
Here is a link to an example of what I do : https://playground.jsreport.net/w/anon/Pm_vIEwF
Here is how I setup the example :
- I prepared my two word
- Right click > new entity > template
- Select handdlebars and docx > next > next
- Click on my template > in properties, in docx I upload my main.docx
- Right click > new entity > asset > upload, i put my subreport.docx
答案1
得分: 0
The docxChild
feature works by searching a docx asset and takes the content of such docx and inserts it into the docx it was called from. You have followed the right steps, but the only issue is that you are using different characters for the quotes in your docxChild
helper call. It was perhaps not your intention, for example on macOS I noticed that whenever I try to use "
, it replaces it with the characters present in your docx, so maybe if you are using macOS, this is the problem you are having.
What it should look like to have it working
I've prepared a playground example with your same code but fixing the docxChild
call to use the right quote characters ""
.
英文:
The docxChild
feature works by searching a docx asset and take the content of such docx and insert it into the docx it was called from. You have follow the right steps, but the only issue is that you are using different characters for the quotes in your docxChild
helper call. It was perhaps not your intention, for example on macos i noticed that whenever i try to use "
it replace it for the characters present in your docx, so maybe if you are using macos this is the problem you are having.
What should look like to have it working
I've prepared a playground example with your same code but fixing the docxChild
call to use the right quote characters ""
,
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论