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 :
Here my output file :