StimVinsh / xdocreport

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

Manage complex table #36

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Issue created in the http://code.google.com/p/xdocreport/issues/detail?id=29 : 

-------------------------------------------------------------------
I have a complex data structure which at its most basic is a list within a
list. Is it possible to add the inner list as a FieldsMetadata element and
loop over the inner list in a table? eg
metadata.addFieldAsList("list.innerlist.data1");
metadata.addFieldAsList("list.innerlist.data2");
Then use the loop functionality to iterate over the first list generating
a table and each inner list generating the rows within each table.

I would also like to be able to generate a table with an unknown number of
columns, repeating over the elements in a list creating a new table cell
for each element. Similar to the row loop functionality but applied to
table cells.

Both of these approaches are possible using the '@' and '@/' notation in
JOD reports, see http://jodreports.sourceforge.net/?q=node/26, but I am
struggling to get the same results using xdoc.
-------------------------------------------------------------------

Original issue reported on code.google.com by angelo.z...@gmail.com on 1 Sep 2011 at 7:11

GoogleCodeExporter commented 8 years ago
Hi Eamon,

If I understand, you wish loop a table row and in a table cell you have an 
another table where you wish loop for table row. Is that? I have never tested 
but it looks like the same subject than 
http://code.google.com/p/xdocreport/issues/detail?id=32

"Generate a table with an unknown number of columns" is not possible for the 
moment. I will try to implement that. I know JOD reports which uses  '@' and 
'@/' notation, it's very powerfull because you can manage as you wish loop for 
table row, etc. 

But goal of XDocReport is to create report with MS Word or OpenOffice with a 
very simple mean. I think that add a jooscript and type Freemarker code to 
manage list of table row is very complex for a person like secretary. With JOD 
reports loop are managed in the ODT document, although with XDocReport loop are 
managed with Java by using FieldMedata. Hope I have explained well our choice.

Regards Angelo 

Original comment by angelo.z...@gmail.com on 1 Sep 2011 at 7:23

GoogleCodeExporter commented 8 years ago
The first part is not the same as issue 32. I want to loop over a set of data 
in the document which will at some point contain a table which is repeated once 
for every section in the document. Within that table I also want to loop over 
the inner list generating the table rows. I thought I might be able to do this 
with the current version, 0.9.1, using the FieldMetadata but I always get an 
error. It seems that the first element named in the FieldMetadata must be the 
collection and the second element the data item to be displayed. eg
metadata.addFieldAsList("collection.data");

I wanted to add
metadata.addFieldAsList("tableCollection.rowCollection.data");
or
metadata.addFieldAsList("object.tableCollection.object.rowCollection.data");
but the current functionality doesn't seem to support it.

I don't think the idea of '@' notation is too complex for a secretary to 
understand. It could be simplified form '@table:table-row' to '@row' and 
'@cell' to remove the need to know the xml structure of the document. It would 
also remove the need for a programmer to add items using FieldMetadata and 
allow some more powerful, optional, functionality.
eg
«@row[#list developers as developer]»«${developer.name}» | 
«${developer.lastName}» | «${developer.mail}»«@/row[/#list]»

Original comment by eamon.wa...@evaluefe.com on 1 Sep 2011 at 9:53

GoogleCodeExporter commented 8 years ago
Ok Eamon,

XDocReport must be improved with your suggestion.
Is is possible for you to attach a sample with:

* the ODT source that you want to write.
* the Java code with context + fieldsmetadata
* the ODT output that you want to obtain.

I think it should be more easy to understand your need instead of explaining 
with message your requirement.

Thank a lot.

Regards Angelo

Original comment by angelo.z...@gmail.com on 1 Sep 2011 at 10:11

GoogleCodeExporter commented 8 years ago
I would like to get the given output file based on the object structure in the 
attached java files.

Original comment by eamon.wa...@evaluefe.com on 6 Sep 2011 at 1:00

GoogleCodeExporter commented 8 years ago
Hi Eamon,

Thank a lot for your sample. I will though how to manage your case.

Regards Angelo

Original comment by angelo.z...@gmail.com on 6 Sep 2011 at 1:50

GoogleCodeExporter commented 8 years ago
Hi Eamon,

I have started to work about your idea about @row. At first instead-of using 
@row and @/row, I have used @start-row and @end-row.

I have attached docx (source and out) to check if you are OK with the idea. The 
sample manage several table samples with @start-row and @end-row: 

* you have a table (like DocxProjectWithFreemarkerAndImageInnerList.docx ) but 
without fieldsmetdata : 

--------------------------------------------------------------------------------
----
«@start-row[#list developers as d]» | «${d.lastName}» | ${d.mail}
«${d.name}»                         |                 |
«@end-row[/#list]»                  |                 |
--------------------------------------------------------------------------------
----

* I have modified the data model and now Developer has a list of Role 
(Developer#getRoles()). The second sample loop for developer list and generates 
a table which contains the roles (your pets sample).

«[#list developers as d]»

Name : «${d.name}»
--------------------------------------------------------------------------------
----
«@start-row[#list d.roles  as r]»«${r.name}»«@end-row[/#list]»
--------------------------------------------------------------------------------
----

«[/#list]»

* table which manage odd/even : 

--------------------------------------------------------------------------------
----
«@start-row[#list developers as d]  | «${d.lastName}» | ${d.mail}
[#if d_index % 2 == 0]»
«${d.name}»                         |                 |
«@end-row[#else]»                   |                 |
--------------------------------------------------------------------------------
----
«${d.name}»«@end-row[/#if][/#list]» | «${d.lastName}» | ${d.mail}
--------------------------------------------------------------------------------
----

If you like this idea, I could commit after having developped some JUnit, 
developping the same feature for ODT.

Thank a lot for this great idea. The report is more complex but you can manage 
powerfull reporting. This feature is for developer and not for secretary.

I will though about cell feature loop. Is it possible to attach a docx sample 
with your idea?

Thank a lot.

Regards Angelo

Original comment by angelo.z...@gmail.com on 7 Sep 2011 at 1:30

Attachments:

GoogleCodeExporter commented 8 years ago
I have added a repeating table cell structure to the end of the document. The 
markup should output data in a similar fashion to database select statement 
output assuming a matching java object structure.

Original comment by eamon.wa...@evaluefe.com on 7 Sep 2011 at 4:40

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Eamon,

Thank  for your sample.

I have commited my work with @start-row on the Git repository. You can find 
samples for Freemarker/Velocity and docx or odt. For instance 
http://code.google.com/p/xdocreport/source/browse/samples/fr.opensagres.xdocrepo
rt.samples.docxandfreemarker/src/fr/opensagres/xdocreport/samples/docxandfreemar
ker/

I will study your docx to see how to manage your need with cell.

Regards Angelo

Original comment by angelo.z...@gmail.com on 7 Sep 2011 at 8:44

GoogleCodeExporter commented 8 years ago
Hi Eamon,

For your information I have written doc about your idea : 

* 
http://code.google.com/p/xdocreport/wiki/DocxReportingJavaMainListFieldAdvancedT
able for docx.
* 
http://code.google.com/p/xdocreport/wiki/ODTReportingJavaMainListFieldAdvancedTa
ble for odt.

You will see some usecase (that you can find in sample) and you will notice 
that I have changed token with @before-row and @after-row. But this token can 
be configurated with FieldsMetadata (see doc).

Loop for cell is not managed. I tell me if we will have problem with table 
column? Do you know if the cell loop features works with JODReports?

Regards Angelo

Original comment by angelo.z...@gmail.com on 8 Sep 2011 at 2:36

GoogleCodeExporter commented 8 years ago
Hi Angelo

There may be problems with table columns if you do not create the same number 
of table cells for each row, but this should be a runtime issue not compile 
time. The '@' annotation in JOD reports allowed markup to be put before or 
after any xml element so could be used to loop over a list generating table 
cells. When doing this I was always careful to ensure the correctness of the 
java data structure before passing it to the JOD reports converter.

Regards

Eamon

Original comment by eamon.wa...@evaluefe.com on 8 Sep 2011 at 3:02

GoogleCodeExporter commented 8 years ago
Hi Eamon,

Thank a lot for your information. I will study that.
As you seem know very well JODReports, I tell me which are the reason that you 
wish use XDocReport instead of JODReports? I think JODReports is more stable 
and provide some features (manage size of image with the report, manage '@' 
annotation with generic mean, etc) compared to XDocReport because it's not a 
young project. But for me XDocReport is more modular than JODReports : 

* manage docx and odt or you can implement your document type?.
* manage Velocity and Freemarker or you can implement your template engine type?
* manage convertion (PDF via IText, XHTML via POI for docx and XHTML via ODFDOM 
for odt) or you can implement your converter.
* I think XDocReport is more performant because it use Velocity/Freemarker 
cache and processing to modify XML is done one time(the first report 
generation).
* design with OSGi.
* WEB Application support, struts2 support, JBoss Seam Report support

But I am not objective and I would know your reason if possible why you wish to 
use XDocReport instead of JODReports?

Thank a lot for your answer.

Regards Angelo

Original comment by angelo.z...@gmail.com on 9 Sep 2011 at 7:49

GoogleCodeExporter commented 8 years ago
Hi Angelo,

The main reason is the docx support without the need to do conversion. I can't 
rely on the open office conversion method so need a library that doesn't use 
it. I originally converted JOD to work with docx instead of odt but when the 
xdoc project started I realised it would probably be a better long term 
solution.

I don't see why the image size and more @ notation options can't be added to 
xdoc as the project continues, any feature that appears in JOD should be able 
to be applied to this project as it matures.

Regards

Eamon

Original comment by eamon.wa...@evaluefe.com on 9 Sep 2011 at 8:23

GoogleCodeExporter commented 8 years ago
Eamon

Thank a lot for your answer. I understand more why you wish use XDocReport. We 
are happy that you are interesting about XDocReport. For the image size and @ 
notation, it's possible to implement that (I will do that), but it's just a 
problem with time.

I think we could create soon (next week, I think) a new release with 
@before-row/@after-row and fix problem with hyperlink. I will study if 
@before-cell/@after-cell  is easy to implement. If it's complex, th erelase 
will not contain this feature.

Regards Angelo

Original comment by angelo.z...@gmail.com on 9 Sep 2011 at 8:37

GoogleCodeExporter commented 8 years ago
Hi Angelo,

Would the name before-cell/after-cell clash with the cell element in a 
spreadsheet implementation? Would before-tableCell/after-tableCell be a better 
choice? Does it matter?

Regards

Eamon

Original comment by eamon.wa...@evaluefe.com on 9 Sep 2011 at 8:43

GoogleCodeExporter commented 8 years ago
Hi Eamon,

I have done a big refactoring to manage '@' and '@/' notation but you can use 
before-row/after-row and before-cell/after-cell too. I prefer using  
before-cell/after-cell before-tableCell/after-tableCell because the token is 
more short. But if you don't like this token you can change it with 
FieldsMedata.

I have tried to play with  before-cell/after-cell with docx and it works well 
(see DocxTableWithoutFieldsMetadataWithFreemarker.docx from 
http://code.google.com/p/xdocreport/source/browse/samples/fr.opensagres.xdocrepo
rt.samples.docxandfreemarker/src/fr/opensagres/xdocreport/samples/docxandfreemar
ker/)

But with ODT it doesn't work because <table-column is important and you must 
have a loop for table-column but how to manage that? Have you a sample with ODT 
which loop for cell with JODReports?

I think we will do a release this week.

Thnak's

Regards Angelo

Original comment by angelo.z...@gmail.com on 14 Sep 2011 at 8:25

GoogleCodeExporter commented 8 years ago
Hi Angelo,

Sorry for the delay in getting back to you. I don't have an ODT example. I only 
tried loop for cell in docx. 

Original comment by eamon.wa...@evaluefe.com on 15 Sep 2011 at 9:06

GoogleCodeExporter commented 8 years ago
Hi Angelo,

The latest build does not always process before-row/after-row. The examples 
given have <w:fldSimple w:instr=" MERGEFIELD  "@before-row[#list developers as 
d]"  \* MERGEFORMAT "> in the generated document.xml. The version of ms word I 
am using understands the fldsimple element but does not use it when inserting 
fields. When generating documents I see <w:instrText xml:space="preserve"> 
MERGEFIELD  "@before-row[#list developers as d]"  \* MERGEFORMAT 
</w:instrText>. When I open the test documents word is in "compatibility mode" 
when I convert the document to a newer format all existing fldsimple elements 
are converted to instrText elements.

The attached files are based on the sample 
DocxTableWithoutFieldsMetadataWithFreemarker.docx file

Original comment by eamon.wa...@evaluefe.com on 3 Oct 2011 at 3:59

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Eamon,

Thank a lot for your helpfull comments! As you have noticed MS Word manages 
mergefield with 2 means : 

* w:fldSimple
* w:instrText

I have never understand why? Indeed I have forgotten to pre-process w:instrText 
-(
I have fixed preprocessing with w:instrText and commited in the Git repository. 
It works with your attached docx and there is a new JUnit 
http://code.google.com/p/xdocreport/source/browse/integrationtests/fr.opensagres
.xdocreport.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/prepr
ocessor/DocxPreprocessorStartStopRowTestCase.java

If you are afraid with Git and m2Eclipse, Pascal have written a great 
documentation at http://code.google.com/p/xdocreport/wiki/ContributorHowTo

Regards Angelo

Original comment by angelo.z...@gmail.com on 4 Oct 2011 at 7:37

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 19 Jan 2012 at 11:48

GoogleCodeExporter commented 8 years ago
Hi,

considering comment 1 back from 2011. Is it still not possible to
"Generate a table with an unknown number of columns"?

I want to create a table similar to
http://wiki.xdocreport.googlecode.com/git/screenshots/DocxProjectWithVelocityLis
t_Out.png

Except i want it ordered like this: 

Name | Zerr | Leclercq
LastName | Angelo | Pascal 
Email | ...

So i want to add a column instead of a row.

Is this possible, if yes how?

Thanks a lot

Regards

Axel

Original comment by der...@googlemail.com on 28 Nov 2012 at 9:45

GoogleCodeExporter commented 8 years ago
For docx it works.See using of before-cell/after-cell with docx in the  
DocxTableWithoutFieldsMetadataWithFreemarker.docx from 
http://code.google.com/p/xdocreport/source/browse/samples/fr.opensagres.xdocrepo
rt.samples.docxandfreemarker/src/fr/opensagres/xdocreport/samples/docxandfreemar
ker/)

For odt, it doesn't work.

Regards Angelo

Original comment by angelo.z...@gmail.com on 28 Nov 2012 at 9:57

GoogleCodeExporter commented 8 years ago
Hi Angelo,

works perfectly, thanks!

now if i wanted to put an image into the foreach loop, i tried the 

fieldMetadata.addFieldAsImage("photo", "people.photo");

approach with the "template" image which works great if i wanted to create a 
list where new rows are generated.

but now i want the imagelist to create new columns. 

Original comment by der...@googlemail.com on 28 Nov 2012 at 12:54

GoogleCodeExporter commented 8 years ago
Never tested this case. I don't know if we can do that with FieldsMetadata. 
Please attach your docx +java code to check if it's possible.

Original comment by angelo.z...@gmail.com on 28 Nov 2012 at 1:08

GoogleCodeExporter commented 8 years ago
hi,

ive used your DocxProjectWithVelocityAndImageList sample and modified it to 
demonstrate my case.

Original comment by der...@googlemail.com on 28 Nov 2012 at 1:49