var d1 = “28/02, 31/05, 30/11”
<<var [d1.substring(0,5)]>>
<<[d1]:"dd MMM yyyy">>
var d1 = “28/02, 31/05, 30/11”
<<var [d1.substring(0,5)]>>
<<[d1]:"dd MMM yyyy">>
@Prashant_Malpure To format value as a date, the variable type should be Date
. So you should either pass the values as a Date
:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("<<[myDate]:\"dd MMM yyyy\">>");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, new Date(), "myDate");
doc.save("C:\\Temp\\out.docx");
or cast the string to Date
:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("<<var [myDate = MyUtil.parseDate(d1.substring(0,5))]>>");
builder.write("<<[myDate]:\"dd MMM yyyy\">>");
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(MyUtil.class);
engine.buildReport(doc, "28/02, 31/05, 30/11", "d1");
doc.save("C:\\Temp\\out.docx");
import java.text.SimpleDateFormat;
import java.util.Date;
public class MyUtil {
public static Date parseDate(String input) throws Exception {
SimpleDateFormat format = new SimpleDateFormat("dd/MM");
return format.parse(input);
}
}
@alexey.noskov Thanks for the quick workaround but I want to do this logic on template side only, can you please help me on that.