Reporting tool in Java

J

Jujo

Hello.

Does anyone know a reporting tool in Java, which can load a template
(previously made in Word or other word processor, for example) and fill in
defined fields ? (inside the report are some sophisticated features which
cannot be achieved with iReport + JasperReport)

Regards,
Jujo
 
S

Stefan Ram

Jujo said:
Does anyone know a reporting tool in Java, which can load a
template (previously made in Word or other word processor, for
example) and fill in defined fields ? (inside the report are
some sophisticated features which cannot be achieved with
iReport + JasperReport)

With Microsoft® Word installed, one can use a COM brigde to
open Microsoft® Word and control it from within a Java
program to instantiate and print the template.

This way, one does not have to write Java code to parse and
interpret Microsoft® Word files.

Otherwise, in order to instantiate a custom template (not a
Microsoft® Word template) in Java one does not need a library
for simple cases.

public class Main
{
public static java.lang.String replace
( final java.lang.String template,
final java.util.Map<java.lang.String,java.lang.String> map )
{ final java.lang.StringBuilder list =
new java.lang.StringBuilder( "\\$(" );
for( final java.lang.String key: map.keySet() )
{ list.append( key ); list.append( "|" ); }
list.append( "[^\\s\\S])" );
java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile( list.toString() );
java.util.regex.Matcher matcher = pattern.matcher( template );
final java.lang.StringBuffer stringBuffer = new java.lang.StringBuffer();
while( matcher.find() )
{ final java.lang.String string = matcher.group( 1 );
matcher.appendReplacement
( stringBuffer, map.get( string )); }
matcher.appendTail( stringBuffer );
return stringBuffer.toString(); }

public static void main( final java.lang.String[] args )
{ final java.util.Map<java.lang.String,java.lang.String> map =
new java.util.HashMap<java.lang.String,java.lang.String>();
map.put( "user", "Mary" );
map.put( "name", "Patricia" );
java.lang.System.out.println
( replace( "Hello $user, my name is $name.", map ) ); }}
 
J

Jujo

Well, I`ll be running my application on AIX server, so there won`t be any
Microsoft in it :)
Any other ideas?

jujo

Stefan Ram said:
Jujo said:
Does anyone know a reporting tool in Java, which can load a
template (previously made in Word or other word processor, for
example) and fill in defined fields ? (inside the report are
some sophisticated features which cannot be achieved with
iReport + JasperReport)

With Microsoft® Word installed, one can use a COM brigde to
open Microsoft® Word and control it from within a Java
program to instantiate and print the template.

This way, one does not have to write Java code to parse and
interpret Microsoft® Word files.

Otherwise, in order to instantiate a custom template (not a
Microsoft® Word template) in Java one does not need a library
for simple cases.

public class Main
{
public static java.lang.String replace
( final java.lang.String template,
final java.util.Map<java.lang.String,java.lang.String> map )
{ final java.lang.StringBuilder list =
new java.lang.StringBuilder( "\\$(" );
for( final java.lang.String key: map.keySet() )
{ list.append( key ); list.append( "|" ); }
list.append( "[^\\s\\S])" );
java.util.regex.Pattern pattern =
java.util.regex.Pattern.compile( list.toString() );
java.util.regex.Matcher matcher = pattern.matcher( template );
final java.lang.StringBuffer stringBuffer = new
java.lang.StringBuffer();
while( matcher.find() )
{ final java.lang.String string = matcher.group( 1 );
matcher.appendReplacement
( stringBuffer, map.get( string )); }
matcher.appendTail( stringBuffer );
return stringBuffer.toString(); }

public static void main( final java.lang.String[] args )
{ final java.util.Map<java.lang.String,java.lang.String> map =
new java.util.HashMap<java.lang.String,java.lang.String>();
map.put( "user", "Mary" );
map.put( "name", "Patricia" );
java.lang.System.out.println
( replace( "Hello $user, my name is $name.", map ) ); }}
 
L

Lew

Please do not top-post.
(Posting order corrected.)


Well, I`ll be running my application on AIX server, so there won`t be any
Microsoft in it :)
Any other ideas?

So how are you going to use MS Word to generate the templates? ("... template
.... previously made in Word ...")

Stefan showed you another way. You could also use OpenOffice instead of Word.
You could also use the iText library directly.

- Lew
 
J

Jujo

Lew said:
Please do not top-post.
(Posting order corrected.)






So how are you going to use MS Word to generate the templates? ("...
template ... previously made in Word ...")

Stefan showed you another way. You could also use OpenOffice instead of
Word. You could also use the iText library directly.

- Lew

The thing is - user wants to have reports send back to him via browser in
*.doc format. I can generate template files on any platform - but my
application will run in user`s enviroment on AIX server. So I need a tool
that will (hopefully) take an input in *.doc template and fill in some
marked fields. Am i asking for too much :) ? Google didn`t help :(

Jujo
 
L

Lew

Jujo said:
The thing is - user wants to have reports send back to him via browser in
*.doc format. I can generate template files on any platform - but my
application will run in user`s enviroment on AIX server. So I need a tool
that will (hopefully) take an input in *.doc template and fill in some
marked fields. Am i asking for too much :) ? Google didn`t help :(

If the user is unwilling to consider PDF, then perhaps RTF (rich-text format)
would be viable. It is automatically opened by MS Word as if it were of DOC
format. It is also much less susceptible to viruses and Trojans.

<http://itextdocs.lowagie.com/tutorial/rtf/index.html>

If you want to convince the customer, start showing them the licensing costs
to use MS software to manipulate the DOC format, and point out that it is not
native to AIX. Show them the dollar cost of .doc and they might be more
amenable to .rtf.

- Lew
 
I

Ian Wilson

Lew said:
If the user is unwilling to consider PDF, then perhaps RTF (rich-text
format) would be viable. It is automatically opened by MS Word as if it
were of DOC format. It is also much less susceptible to viruses and
Trojans.

<http://itextdocs.lowagie.com/tutorial/rtf/index.html>

If you want to convince the customer, start showing them the licensing
costs to use MS software to manipulate the DOC format, and point out
that it is not native to AIX. Show them the dollar cost of .doc and they
might be more amenable to .rtf.

Why try to convince them? I'd write RTF into a file with a .doc suffix and
demonstrate it opening in Word perfectly normally. I've certainly done something
very similar and the customers were very happy with the result. Since it meets
the stated requirements I wouldn't confuse the customer with a discussion of
technical underpinnings of no interest to them.
 
S

Stefan Ram

Lew said:
If the user is unwilling to consider PDF, then perhaps RTF (rich-text format)
would be viable. It is automatically opened by MS Word as if it were of DOC
format. It is also much less susceptible to viruses and Trojans.

The following example statement shows how to write an RTF document:

new java,io.FileWriter("example.rtf").append("{\\rtf\\ansi Hi!\par}").close();
 
S

Stefan Ram

Supersedes: <[email protected]>

Lew said:
If the user is unwilling to consider PDF, then perhaps RTF (rich-text format)
would be viable. It is automatically opened by MS Word as if it were of DOC
format. It is also much less susceptible to viruses and Trojans.

The following example statement shows how to write an RTF document:

new java,io.FileWriter("example.rtf").append("{\\rtf\\ansi Hi!\\par}").close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top