1

I Have velocity template like this one :

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| $totalPel  Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

When i put $totalPel -> 100, the result is :

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100  Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

Actually I want to get the result like this :

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100        Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

Anyone can show me how to make it?

I use this java code :

Velocity.init();

VelocityContext context = new VelocityContext();
context.put("totalPel", 100);

Template template = Velocity.getTemplate("LaporanTagihan.txt");

StringWriter writer = new StringWriter();

template.merge(context, writer);

System.out.println(writer.toString());

2 Answers2

5

Pad your strings before adding them to your template. See How can I pad a String in Java? for advice on how to do this.

Community
  • 1
  • 1
mcfinnigan
  • 10,367
  • 30
  • 28
2

You can either transform the value into a String and pad it, or you can simply add more space in your template, I believe velocity maintains whitespace that you define.

pcalcao
  • 15,237
  • 1
  • 40
  • 62