MohamedSaeed / xdocreport

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

I can not print values at my report. #407

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello.

I can not print values at my report. I create on the docx valua a mergefield 
with $Project.hours as field.

I call Project from a class named createFastEvaluation
with the method below:

public void createDocument(){
        try {
            // 1) Load Docx file by filling Velocity template engine and cache it to the registry
            InputStream in = CreateFastEvaluation.class.getResourceAsStream("DocxProjectWithVelocity.docx");
            IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in,TemplateEngineKind.Velocity);

            // 2) Create context Java model
            IContext context = report.createContext();
            Project evaluation = new Project(this.hours);
            context.put("project", evaluation);

            // 3) Generate report by merging Java model with the Docx
            OutputStream out = new FileOutputStream(new File("tsei_ekthesi_aksiologisis_out.docx"));
            report.process(context, out);

          } catch (IOException e) {
            e.printStackTrace();
          } catch (XDocReportException e) {
            e.printStackTrace();
          }
    }

The Project class is as follow:

public class Project {

        private int hours;
        public Project(int hours){
            this.hours=hours;
        }
    /**
     * @return the hours
     */
    public int getHours() {
        return hours;
    }

    /**
     * @param hours the hours to set
     */
    public void setHours(int hours) {
        this.hours = hours;
    }
}

What am i doing wrong? Thanks!!

Original issue reported on code.google.com by linarda...@ebeh.gr on 11 Jun 2014 at 11:22

GoogleCodeExporter commented 9 years ago
Can you try with

$project.Hours

(with H uppercase)

see exemple here : 
https://code.google.com/p/xdocreport/wiki/DocxReportingJavaMain

Original comment by pascal.leclercq on 11 Jun 2014 at 12:08

GoogleCodeExporter commented 9 years ago
If you write 

------------------------------------
context.put("project", evaluation);
------------------------------------

Your key must be "$project" and not "$Project"

Original comment by angelo.z...@gmail.com on 11 Jun 2014 at 12:33

GoogleCodeExporter commented 9 years ago
Thanks a lot. I put project instead of Project and it worked!!! thanks again!!!

Original comment by linarda...@ebeh.gr on 12 Jun 2014 at 5:24

GoogleCodeExporter commented 9 years ago
Ok I close the issue.

Original comment by angelo.z...@gmail.com on 12 Jun 2014 at 6:55