DocxTableWithFieldsMetadataWithVelocity

30 views
Skip to first unread message

Soumaila Doumbia

unread,
Sep 10, 2021, 12:44:26 AM9/10/21
to xdocreport
Hello,

I'm trying to make a docx table with FieldsMetadata and Velocity but in the output file, each cell of the table contains the list itself and not the value of the cell.

Here my code :

// Build Docx
private fun buildDocxReport(): SystemFile {
try {
val resource = this.javaClass.classLoader.getResourceAsStream("reports/code.docx")

val report = XDocReportRegistry.getRegistry().loadReport(resource, TemplateEngineKind.Velocity)

val metadata = report.createFieldsMetadata()
metadata.load("codes", Code::class.java, true)

val context = report.createContext()
context.put("codes", getAllcodes()); // getAllcodes() : return List<Code>

val tempFile = File.createTempFile("${DateUtil.format(Date(), "yyyyMMdd")}_${IDs.short()}", ".docx")
val fos = FileOutputStream(tempFile)

// convert to pdf
//val options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF)
//report.convert(context, options, fos)

report.process(context, fos)
fos.close()

return SystemFile(tempFile).attach(tempFile.name)

} catch (e: Throwable) {
e.printStackTrace()
throw FunctionalException("Impossible de gérer le document. Une erreur s'es produite.")
}
}

Here my template docx file :
Capture du 2021-09-09 13-42-20.png
Here my output file :
Capture du 2021-09-09 14-15-40.png
Reply all
Reply to author
Forward
0 new messages