MohamedSaeed / xdocreport

Automatically exported from code.google.com/p/xdocreport
1 stars 0 forks source link

Is there a way to merge generated Word document? #334

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm not sure, this is not right place to send question. If there is better 
place, pleas close and let me know where can I post.

This is to generate letter (mostly one page) for people. I'd like to generate 
one Word document per person and merge it after.   I know I can make big loop 
for people but merging has its benefit sometimes.

Thanks.

Original issue reported on code.google.com by dennisl...@gmail.com on 26 Nov 2013 at 11:28

GoogleCodeExporter commented 9 years ago
Merge 2 docx is an hard task, so it's out of the scope of XDocReport.

As you has said, you must use a start/end loop to manage that. I have an idea 
to manage this start/end loop with lazily with preprocessor (no need to set the 
start/end loop in the docx, and more you could use the same docx template for a 
loop of person or just one person).

Original comment by angelo.z...@gmail.com on 26 Nov 2013 at 11:36

GoogleCodeExporter commented 9 years ago
I'm not sure what exactly you mean but seem good. I look forward to it.  
One of problem with loop is readability - adding page break per person means 
end loop is in the next page.

Thanks for prompt response.

Original comment by dennisl...@gmail.com on 26 Nov 2013 at 11:45

GoogleCodeExporter commented 9 years ago
> One of problem with loop is readability - adding page break per person means 
end loop is in the next page.

I agree with you, that's why my idea is to generate the start/end loop 
directive with preprocessor. 

Here some explanation about my idea : imagine you wish to generate a report 
with a list of developers and use the same report to generate one developer. 

1) you create your docx like this : 

${developer.name}

2) If you wish to generate a report with just a developer, you do like this : 

------------------------------------------
Developer developer = ....
IContext context = ....
content.put("developer", developer);
------------------------------------------

3) now if you wish to generate a list of developers, you will do like this : 

------------------------------------------
FieldsMetata metadata = ...
metadata.setGlobalLoop("developers","developer");

List<Developer> developers = ....
IContext context = ....
content.put("developers", developers);
------------------------------------------

the use of setGlobalLoop, will add automaticly :

1) [#list developers as developer] on start of the docx.
2) [/#list] on end of the docx.

Original comment by angelo.z...@gmail.com on 27 Nov 2013 at 12:07

GoogleCodeExporter commented 9 years ago
Seems good to me.  Look forward to it. Thanks.

Original comment by dennisl...@gmail.com on 27 Nov 2013 at 12:18

GoogleCodeExporter commented 9 years ago
Another vote for me.

We have exactly the same requirement: create a letter from the same template to 
multiple people.
I already solved this, but it's much uglier than the suggestion. I am also 
using #foreach($contact in $contacts) and I had to replace each tag e.g. 
$salutation with $contact.salutation.

I also have to manage pagebreaks in between persons but not for the last 
person. Somehow I managed to solve this but had had to create a tag 
$contact.pagebreak that is filled with

"<p style=\"page-break-after:always\"></p>"

Original comment by Henno.Ve...@gmail.com on 27 Jan 2014 at 1:53

GoogleCodeExporter commented 9 years ago
If I understand your need : 

1) you wish to avoid writing "#foreach($contact in $contacts)" in the docx.
2) you wish to write "$salutation" instead of writing "$contact.salutation" in 
the docx.
3) you wish to avoid using $contact.pagebreak to manage page break.

If it that, I think it's possible to do it with XDocReport by improving 
preprocessor like I have explained. 

Original comment by angelo.z...@gmail.com on 27 Jan 2014 at 2:00

GoogleCodeExporter commented 9 years ago
<angelo.z...@gmail.com>
Now that I read your post again, it seems what you explained is already 
possible. Right? If so, can you explain more about it please?  I can't 
understand how I can do this.

FieldsMetata  metadata = ...
metadata.setGlobalLoop("developers","developer");

Original comment by dennisl...@gmail.com on 29 May 2014 at 3:07

GoogleCodeExporter commented 9 years ago
Today it's not possible. I had no time to implement this feature.

Original comment by angelo.z...@gmail.com on 29 May 2014 at 9:58

GoogleCodeExporter commented 9 years ago
Sorry. I wasn't sure it is to implement or already in there.  Hope it can be 
added soon. Thanks.

Original comment by dennisl...@gmail.com on 29 May 2014 at 1:20